Module: SlimFormObject::ClassMethods
- Defined in:
- lib/slim_form_object.rb
Instance Method Summary collapse
Instance Method Details
#add_attributes(models) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/slim_form_object.rb', line 22 def add_attributes(models) #attr_accessor for models and env params attr_accessor :params models.each{ |model| attr_accessor snake(model.to_s).to_sym } #delegate attributes of models models.each do |model| model.column_names.each do |attr| delegate attr.to_sym, "#{attr}=".to_sym, to: snake(model.to_s).to_sym, prefix: snake(model.to_s).to_sym end end end |
#init_models(*args) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/slim_form_object.rb', line 15 def init_models(*args) self.instance_eval do define_method(:array_of_models) { args } end add_attributes(args) end |
#set_model_name(name) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/slim_form_object.rb', line 37 def set_model_name(name) @@set_name = name class << self def model_name ActiveModel::Name.new(self, nil, @@set_name.to_s) end end end |