Sha256: 492656128c3c28c61f1a21caf89b528e29109d4ca83ca944f9d5ecfaa31db260

Contents?: true

Size: 1.31 KB

Versions: 30

Compression:

Stored size: 1.31 KB

Contents

module Her
  module Model
    # TODO: make PR to Her project
    # This patch fixes the detection of changed attributes
    module Attributes
      extend ActiveSupport::Concern


      module ClassMethods
        # Define the attributes that will be used to track dirty attributes and validations
        #
        # @param [Array] attributes
        # @example
        #   class User
        #     include Her::Model
        #     attributes :name, :email
        #   end
        def attributes(*attributes)
          define_attribute_methods attributes

          attributes.each do |attribute|
            attribute = attribute.to_sym

            unless instance_methods.include?(:"#{attribute}=")
              define_method("#{attribute}=") do |value|
                @attributes[:"#{attribute}"] = nil unless @attributes.include?(:"#{attribute}")
                self.send(:"#{attribute}_will_change!") if @attributes[:"#{attribute}"] != value
                @attributes[:"#{attribute}"] = value
              end
            end

            unless instance_methods.include?(:"#{attribute}?")
              define_method("#{attribute}?") do
                @attributes.include?(:"#{attribute}") && @attributes[:"#{attribute}"].present?
              end
            end
          end
        end
        
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
mno-enterprise-core-2.0.4 lib/her_extension/model/attributes.rb
mno-enterprise-core-3.1.0 lib/her_extension/model/attributes.rb
mno-enterprise-core-3.0.3 lib/her_extension/model/attributes.rb
mno-enterprise-core-2.0.3 lib/her_extension/model/attributes.rb
mno-enterprise-core-3.0.2 lib/her_extension/model/attributes.rb
mno-enterprise-core-2.0.2 lib/her_extension/model/attributes.rb
mno-enterprise-core-3.0.1 lib/her_extension/model/attributes.rb
mno-enterprise-core-2.0.1 lib/her_extension/model/attributes.rb
mno-enterprise-core-3.0.0 lib/her_extension/model/attributes.rb
mno-enterprise-core-2.0.0 lib/her_extension/model/attributes.rb