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

Version Path
rest-in-peace-6.2.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.1.1 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.1.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.0.4 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.0.3 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.0.2 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-6.0.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-5.1.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-5.0.2 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-5.0.1 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-5.0.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-4.2.1 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-4.2.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-4.1.1 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-4.1.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-4.0.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb
rest-in-peace-3.0.0 lib/rest_in_peace/definition_proxy/attributes_definitions.rb