Module: Mobility::Backend::ActiveModel::Dirty
- Defined in:
- lib/mobility/backend/active_model/dirty.rb
Overview
Dirty tracking for models which include the ActiveModel::Dirty
module.
Assuming we have an attribute title
, this module will add support for the following methods:
-
title_changed?
-
title_change
-
title_was
-
title_will_change!
-
title_previously_changed?
-
title_previous_change
-
restore_title!
In addition, the private method restore_attribute!
will also restore the value of the translated attribute if passed to it.
Defined Under Namespace
Modules: ClassMethods
Backend Accessors collapse
-
#write(locale, value, **options) ⇒ Object
Updated value.
Class Method Summary collapse
Class Method Details
.included(backend_class) ⇒ Object
38 39 40 |
# File 'lib/mobility/backend/active_model/dirty.rb', line 38 def self.included(backend_class) backend_class.extend(ClassMethods) end |
Instance Method Details
#write(locale, value, **options) ⇒ Object
Returns Updated value.
26 27 28 29 30 31 32 33 34 |
# File 'lib/mobility/backend/active_model/dirty.rb', line 26 def write(locale, value, **) locale_accessor = "#{attribute}_#{locale}" if model.changed_attributes.has_key?(locale_accessor) && model.changed_attributes[locale_accessor] == value model.attributes_changed_by_setter.except!(locale_accessor) else model.send(:attribute_will_change!, "#{attribute}_#{locale}") end super end |