Class: RailsFormObject::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/rails_form_object/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Returns a new instance of Base.



20
21
22
# File 'lib/rails_form_object/base.rb', line 20

def initialize(attributes)
  super(filtered_attributes(attributes))
end

Class Method Details

.attributes(*attr) ⇒ Object



10
11
12
13
# File 'lib/rails_form_object/base.rb', line 10

def self.attributes(*attr)
  attr_accessor(*attr)
  define_method(:stored_attributes) { attr }
end

Instance Method Details

#filtered_attributes(attributes) ⇒ Object



15
16
17
18
# File 'lib/rails_form_object/base.rb', line 15

def filtered_attributes(attributes)
  raise AttributesMustBeDefined unless respond_to? :stored_attributes
  attributes.select { |key, _value| stored_attributes.include?(key.to_sym) }
end