Class: ActAsDirty::ActiveModel::Cleaner
- Inherits:
-
Object
- Object
- ActAsDirty::ActiveModel::Cleaner
- Defined in:
- lib/act_as_dirty/active_model/cleaner.rb
Overview
DirtyMe Cleaner
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#clean(record) ⇒ Object
Performs cleaning on the supplied record.
- #clean_each(record, attribute) ⇒ Object
-
#initialize(options) ⇒ Cleaner
constructor
Accepts options that will be made available through the
options
reader.
Constructor Details
#initialize(options) ⇒ Cleaner
Accepts options that will be made available through the options
reader.
12 13 14 15 16 |
# File 'lib/act_as_dirty/active_model/cleaner.rb', line 12 def initialize() @attributes = Array.wrap([:attributes]) raise ":attributes cannot be blank" if @attributes.empty? @options = .freeze end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/act_as_dirty/active_model/cleaner.rb', line 9 def attributes @attributes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/act_as_dirty/active_model/cleaner.rb', line 9 def @options end |
Instance Method Details
#clean(record) ⇒ Object
Performs cleaning on the supplied record. By default this will call clean_each
to determine cleanliness therefore subclasses should override clean_each
with cleaning logic.
21 22 23 24 25 26 27 |
# File 'lib/act_as_dirty/active_model/cleaner.rb', line 21 def clean(record) return unless record.changed? attributes.each do |attribute| next unless record.changes[attribute.to_s] clean_each(record, attribute) end end |
#clean_each(record, attribute) ⇒ Object
29 30 31 |
# File 'lib/act_as_dirty/active_model/cleaner.rb', line 29 def clean_each(record, attribute) record.dirt.set(attribute, (record, attribute)) end |