solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 228 forks source link

Set multiple attributes #327

Closed michaelachrisco closed 8 years ago

michaelachrisco commented 8 years ago

Right now, I use my own very small custom gem called virtus-extras to create multiple like attributes within my form objects like so:

require 'active_model'
require 'active_support'
require 'virtus/extras'

class UserEntry
  include Virtus.model

  extend ActiveModel::Naming
  include ActiveModel::Conversion
  extend Virtus::Extras::FormObject

  form_attributes :first_name,
                  :last_name,
                  :display_name,
                  :model => String

  form_attributes :is_active,
                  :model => Integer

  form_attributes :hidden,
                  :model => Integer,
                  :writer => :private
end

The meat and potatoes are here: https://github.com/michaelachrisco/virtus-extras/blob/master/lib/virtus/extras/form_object.rb

I was wondering if this kind of implementation would be welcome within the main gem? I understand this is more of a personal preference (given that the syntax is more akin to ruby validation).

Thoughts and opinions? Also apologies if there is already some method that does this.

michaelachrisco commented 8 years ago

Gem takes care of this format. Closing.,