module Elastictastic::Dirty::ClassMethods

Public Instance Methods

define_embed(embed_name, options) click to toggle source
Calls superclass method
# File lib/elastictastic/dirty.rb, line 15
def define_embed(embed_name, options)
  super
  define_dirty_accessors(embed_name)
end
define_field(field_name, options, &block) click to toggle source
Calls superclass method
# File lib/elastictastic/dirty.rb, line 10
def define_field(field_name, options, &block)
  super
  define_dirty_accessors(field_name)
end

Private Instance Methods

define_dirty_accessors(attribute) click to toggle source

We have to rewrite ActiveModel functionality here because in Rails 3.0, define_attribute_methods has to be called exactly one time, and there’s no place for us to do that. This appears to be fixed in ActiveModel 3.1

# File lib/elastictastic/dirty.rb, line 27
      def define_dirty_accessors(attribute)
        attribute = attribute.to_s
        module_eval <<-RUBY, __FILE__, __LINE__+1
          def #{attribute}_changed?
            attribute_changed?(#{attribute.inspect})
          end

          def #{attribute}_change
            attribute_change(#{attribute.inspect})
          end

          def #{attribute}_will_change!
            attribute_will_change!(#{attribute.inspect})
          end

          def #{attribute}_was
            attribute_was(#{attribute.inspect})
          end

          def reset_#{attribute}!
            reset_attribute!(#{attribute})
          end
        RUBY
      end