Sha256: bea8ec3cfd7f8f6247556db3e9b43b2626f61a8b298be1bda719614d7b8f6edf

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

module AttributeChangedSpecification
  module ::ActiveModel
    module Dirty

      private

        def attribute_changed_with_specification?(attr, *args)
          if args.empty?
            attribute_changed_without_specification?(attr)
          else
            return false unless self.changes.include?(attr)
            from = args[0][:from]
            to   = args[0][:to]

            if from && to
              self.changes[attr][0] == from && __send__(attr) == to
            elsif from
              self.changes[attr][0] == from
            elsif to
              __send__(attr) == to
            else
              attribute_changed_without_specification?(attr, args)
            end
          end
        end
        alias_method_chain :attribute_changed?, :specification

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activemodel-attribute_changed_specification-0.1.3 lib/active_model/attribute_changed_specification/specification.rb
activemodel-attribute_changed_specification-0.1.2 lib/active_model/attribute_changed_specification/specification.rb