Sha256: 016a255daedb88ef2bef9d2aff83bf489027b7a64274bedaa2ef7f6eec9ad58d
Contents?: true
Size: 1.09 KB
Versions: 17
Compression:
Stored size: 1.09 KB
Contents
module RESTinPeace class DefinitionProxy class AttributesDefinitions def initialize(target) @target = target end def read(*attributes) @target.send(:attr_reader, *attributes) @target.rip_attributes[:read].concat(attributes) end 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 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 end end end
Version data entries
17 entries across 17 versions & 1 rubygems