Class: ActiveRecord::Journal::Journable::Context
- Inherits:
-
Object
- Object
- ActiveRecord::Journal::Journable::Context
- Defined in:
- lib/active_record/journal/journable/context.rb
Defined Under Namespace
Classes: Storage
Instance Attribute Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
- #configured_for?(action) ⇒ Boolean
-
#initialize(**tags_args) ⇒ Context
constructor
A new instance of Context.
- #record(journable, type = nil, **with) ⇒ Object
- #rules ⇒ Object
- #tag(tags_class) ⇒ Object
Constructor Details
#initialize(**tags_args) ⇒ Context
Returns a new instance of Context.
35 36 37 |
# File 'lib/active_record/journal/journable/context.rb', line 35 def initialize(**) @tags_args = end |
Instance Attribute Details
#generate_tag ⇒ Object
61 62 63 |
# File 'lib/active_record/journal/journable/context.rb', line 61 def generate_tag @generate_tag || false end |
#ignore_actions ⇒ Object
57 58 59 |
# File 'lib/active_record/journal/journable/context.rb', line 57 def ignore_actions @ignore_actions || false end |
Instance Method Details
#actions ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/active_record/journal/journable/context.rb', line 49 def actions ActiveRecord::Journal.context_override = self yield ActiveRecord::Journal.context_override = nil rescue StandardError ActiveRecord::Journal.context_override = nil end |
#configured_for?(action) ⇒ Boolean
39 40 41 |
# File 'lib/active_record/journal/journable/context.rb', line 39 def configured_for?(action) rules.search_by(action: action.to_s)&.any? || false end |
#record(journable, type = nil, **with) ⇒ Object
43 44 45 46 47 |
# File 'lib/active_record/journal/journable/context.rb', line 43 def record(journable, type = nil, **with) = ActiveRecord::Journal::Journable::Options.parse(with, type) rule = ActiveRecord::Journal::Journable::Rule.new(journable, ) .on.each { |action| rules.add(action: action, journable: journable, rule: rule) } end |
#rules ⇒ Object
65 66 67 |
# File 'lib/active_record/journal/journable/context.rb', line 65 def rules @rules ||= Storage.new end |
#tag(tags_class) ⇒ Object
69 70 71 72 73 |
# File 'lib/active_record/journal/journable/context.rb', line 69 def tag() return @tag if defined?(@tag) @tag = .create!(**@tags_args) if generate_tag end |