class RESTinPeace::DefinitionProxy::AttributesDefinitions
Public Class Methods
new(target)
click to toggle source
# File lib/rest_in_peace/definition_proxy/attributes_definitions.rb, line 4 def initialize(target) @target = target end
Public Instance Methods
read(*attributes)
click to toggle source
# File lib/rest_in_peace/definition_proxy/attributes_definitions.rb, line 8 def read(*attributes) @target.send(:attr_reader, *attributes) @target.rip_attributes[:read].concat(attributes) end
write(*attributes)
click to toggle source
# File lib/rest_in_peace/definition_proxy/attributes_definitions.rb, line 13 def write(*attributes) read(*attributes) @target.send :attr_writer, *attributes @target.send :define_attribute_methods, attributes @target.rip_attributes[:write].concat(attributes) attributes.each do |attribute| define_dirty_tracking attribute end end
Private Instance Methods
define_dirty_tracking(attribute)
click to toggle source
# File lib/rest_in_peace/definition_proxy/attributes_definitions.rb, line 26 def define_dirty_tracking(attribute) @target.send(:define_method, "#{attribute}_with_dirty_tracking=") do |value| attribute_will_change!(attribute) unless send(attribute) == value send("#{attribute}_without_dirty_tracking=", value) end @target.send(:alias_method, "#{attribute}_without_dirty_tracking=", "#{attribute}=") @target.send(:alias_method, "#{attribute}=", "#{attribute}_with_dirty_tracking=") end