class ForgedModel::Model
Public Class Methods
define_attributes(*methods)
click to toggle source
# 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
new(params={})
click to toggle source
Calls superclass method
ActiveModel::Model::new
# File lib/forged_model/model.rb, line 31 def initialize(params={}) load(params) changed_attributes.clear super() end
Public Instance Methods
attributes()
click to toggle source
# 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
Protected Instance Methods
load(params)
click to toggle source
# File lib/forged_model/model.rb, line 45 def load(params) params.each do |attr, value| self.public_send("#{attr}=", value) end if params end