123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Changeable::ClassMethods

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/changeable.rb

Overview

Class-level methods for changeable objects.

Instance Method Summary

Instance Method Details

#create_dirty_change_accessor(name, meth) (private)

Creates the dirty change accessor.

Examples:

Create the accessor.

Model.create_dirty_change_accessor("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 383

def create_dirty_change_accessor(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_change") do
      attribute_change(name)
    end
  end
end

#create_dirty_change_check(name, meth) (private)

Creates the dirty change check.

Examples:

Create the check.

Model.create_dirty_change_check("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 398

def create_dirty_change_check(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_changed?") do |**kwargs|
      attribute_changed?(name, **kwargs)
    end
    re_define_method("will_save_change_to_#{meth}?") do |**kwargs|
      will_save_change_to_attribute?(name, **kwargs)
    end
  end
end

#create_dirty_change_flag(name, meth) (private)

Creates the dirty change flag.

Examples:

Create the flag.

Model.create_dirty_change_flag("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 458

def create_dirty_change_flag(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_will_change!") do
      attribute_will_change!(name)
    end
  end
end

#create_dirty_default_change_check(name, meth) (private)

Creates the dirty default change check.

Examples:

Create the check.

Model.create_dirty_default_change_check("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 416

def create_dirty_default_change_check(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_changed_from_default?") do
      attribute_changed_from_default?(name)
    end
  end
end

#create_dirty_methods(name, meth) ⇒ Module (private)

Generate all the dirty methods needed for the attribute.

Examples:

Generate the dirty methods.

Model.create_dirty_methods("name", "name")

Parameters:

  • name (String)

    The name of the field.

  • meth (String)

    The name of the accessor.

Returns:

  • (Module)

    The fields module.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 364

def create_dirty_methods(name, meth)
  create_dirty_change_accessor(name, meth)
  create_dirty_change_check(name, meth)
  create_dirty_change_flag(name, meth)
  create_dirty_default_change_check(name, meth)
  create_dirty_previous_value_accessor(name, meth)
  create_dirty_reset(name, meth)
  create_dirty_reset_to_default(name, meth)
  create_dirty_previously_changed?(name, meth)
  create_dirty_previous_change(name, meth)
end

#create_dirty_previous_change(name, meth) (private)

Creates the dirty change accessor.

Examples:

Create the dirty change accessor.

Model.create_dirty_previous_change("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 518

def create_dirty_previous_change(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_previous_change") do
      previous_changes[name]
    end
  end
end

#create_dirty_previous_value_accessor(name, meth) (private)

Creates the dirty change previous value accessors.

Examples:

Create the accessor.

Model.create_dirty_previous_value_accessor("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 431

def create_dirty_previous_value_accessor(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_was") do
      attribute_was(name)
    end
    re_define_method("#{meth}_previously_was") do
      attribute_previously_was(name)
    end
    re_define_method("#{meth}_before_last_save") do
      attribute_before_last_save(name)
    end
    re_define_method("saved_change_to_#{meth}") do
      saved_change_to_attribute(name)
    end
    re_define_method("saved_change_to_#{meth}?") do |**kwargs|
      saved_change_to_attribute?(name, **kwargs)
    end
  end
end

#create_dirty_previously_changed?(name, meth) ⇒ Boolean (private)

Creates the dirty change check.

Examples:

Create the dirty change check.

Model.create_dirty_previously_changed?("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 503

def create_dirty_previously_changed?(name, meth)
  generated_methods.module_eval do
    re_define_method("#{meth}_previously_changed?") do
      previous_changes.key?(name)
    end
  end
end

#create_dirty_reset(name, meth) (private)

Creates the dirty change reset.

Examples:

Create the reset.

Model.create_dirty_reset("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 473

def create_dirty_reset(name, meth)
  generated_methods.module_eval do
    re_define_method("reset_#{meth}!") do
      reset_attribute!(name)
    end
  end
end

#create_dirty_reset_to_default(name, meth) (private)

Creates the dirty change reset to default.

Examples:

Create the reset.

Model.create_dirty_reset_to_default("name", "alias")

Parameters:

  • name (String)

    The attribute name.

  • meth (String)

    The name of the accessor.

[ GitHub ]

  
# File 'lib/mongoid/changeable.rb', line 488

def create_dirty_reset_to_default(name, meth)
  generated_methods.module_eval do
    re_define_method("reset_#{meth}_to_default!") do
      reset_attribute_to_default!(name)
    end
  end
end