Class: ActiveRecord::Journal::Journable::Callback
- Inherits:
-
Object
- Object
- ActiveRecord::Journal::Journable::Callback
- Defined in:
- lib/active_record/journal/journable/callback.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
Instance Method Summary collapse
-
#call(record) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength.
-
#initialize(action) ⇒ Callback
constructor
A new instance of Callback.
- #to_proc ⇒ Object
Constructor Details
#initialize(action) ⇒ Callback
Returns a new instance of Callback.
9 10 11 |
# File 'lib/active_record/journal/journable/callback.rb', line 9 def initialize(action) @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/active_record/journal/journable/callback.rb', line 7 def action @action end |
Instance Method Details
#call(record) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_record/journal/journable/callback.rb', line 18 def call(record) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength return unless valid_context? override = rules_for(context: context_override, record: record) || {} rules = rules_for(context: record.class.journable_context, record: record) rules&.each do |journal, list| list.each do |rule| next unless rules_met?(rule: rule, override: override[journal], record: record) attributes = Attributes.new(record, rule).tracked_keys changes = Changes.new(record, action, attributes, rule.mask).call context = context_override || record.class.journable_context record_changes( changes: changes, record: record, entries_class: rule.entries_class, tag: context.tag(rule.) ) end end end |
#to_proc ⇒ Object
13 14 15 16 |
# File 'lib/active_record/journal/journable/callback.rb', line 13 def to_proc callback = self ->(record) { callback.call(record) } end |