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
-
#create_dirty_change_accessor(name, meth)
private
Creates the dirty change accessor.
-
#create_dirty_change_check(name, meth)
private
Creates the dirty change check.
-
#create_dirty_change_flag(name, meth)
private
Creates the dirty change flag.
-
#create_dirty_default_change_check(name, meth)
private
Creates the dirty default change check.
-
#create_dirty_methods(name, meth) ⇒ Module
private
Generate all the dirty methods needed for the attribute.
-
#create_dirty_previous_change(name, meth)
private
Creates the dirty change accessor.
-
#create_dirty_previous_value_accessor(name, meth)
private
Creates the dirty change previous value accessors.
-
#create_dirty_previously_changed?(name, meth) ⇒ Boolean
private
Creates the dirty change check.
-
#create_dirty_reset(name, meth)
private
Creates the dirty change reset.
-
#create_dirty_reset_to_default(name, meth)
private
Creates the dirty change reset to default.
Instance Method Details
#create_dirty_change_accessor(name, meth) (private)
Creates the dirty change accessor.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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.
# 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