Class: Esse::ActiveRecord::Callbacks::UpdateLazyAttribute
- Inherits:
-
Esse::ActiveRecord::Callback
- Object
- Esse::ActiveRecord::Callback
- Esse::ActiveRecord::Callbacks::UpdateLazyAttribute
- Defined in:
- lib/esse/active_record/callbacks/update_lazy_attribute.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
Attributes inherited from Esse::ActiveRecord::Callback
#block_result, #options, #repo
Instance Method Summary collapse
- #call(model) ⇒ Object
-
#initialize(attribute_name:, **kwargs, &block) ⇒ UpdateLazyAttribute
constructor
A new instance of UpdateLazyAttribute.
Constructor Details
#initialize(attribute_name:, **kwargs, &block) ⇒ UpdateLazyAttribute
Returns a new instance of UpdateLazyAttribute.
8 9 10 11 |
# File 'lib/esse/active_record/callbacks/update_lazy_attribute.rb', line 8 def initialize(attribute_name:, **kwargs, &block) @attribute_name = attribute_name super(**kwargs, &block) end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
6 7 8 |
# File 'lib/esse/active_record/callbacks/update_lazy_attribute.rb', line 6 def attribute_name @attribute_name end |
Instance Method Details
#call(model) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/esse/active_record/callbacks/update_lazy_attribute.rb', line 13 def call(model) = Esse::ArrayUtils.wrap(block_result || model.id) return true if .empty? repo.update_documents_attribute(attribute_name, , ) true end |