Class: ForgedModel::Model
- Inherits:
-
Object
- Object
- ForgedModel::Model
- Includes:
- ActiveModel::Dirty, ActiveModel::Model, ActiveModel::Serialization
- Defined in:
- lib/forged_model/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(params = {}) ⇒ Model
constructor
A new instance of Model.
Methods included from ActiveModel::Model
Constructor Details
#initialize(params = {}) ⇒ Model
Returns a new instance of Model.
31 32 33 34 35 |
# File 'lib/forged_model/model.rb', line 31 def initialize(params={}) load(params) changed_attributes.clear super() end |
Class Method Details
.define_attributes(*methods) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/forged_model/model.rb', line 15 def define_attributes(*methods) self.attribute_list += methods attr_reader *methods methods.each do |method| class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{method}=(value) #{method}_will_change! @#{method} = value end EOS end define_attribute_methods methods end |
Instance Method Details
#attributes ⇒ Object
37 38 39 40 41 |
# File 'lib/forged_model/model.rb', line 37 def attributes Hash[self.class.attribute_list \ .select{ |name| instance_variable_defined? "@#{name}" } \ .map { |name, _| [name, self.send(name)] }] end |