Class: ActiveRecord::Journal::Journable::Context::Storage
- Inherits:
-
Struct
- Object
- Struct
- ActiveRecord::Journal::Journable::Context::Storage
- Defined in:
- lib/active_record/journal/journable/context.rb
Instance Method Summary collapse
- #add(action:, journable:, rule:) ⇒ Object
-
#initialize ⇒ Storage
constructor
A new instance of Storage.
- #search_by(action:, subject: nil) ⇒ Object
Constructor Details
#initialize ⇒ Storage
Returns a new instance of Storage.
10 11 12 13 14 |
# File 'lib/active_record/journal/journable/context.rb', line 10 def initialize actions = ActiveRecord::Journal::ACTIONS.values.flatten kwargs = actions.each_with_object({}) { |a, map| map[a.to_sym] = {} } super(**kwargs) end |
Instance Method Details
#add(action:, journable:, rule:) ⇒ Object
16 17 18 19 20 |
# File 'lib/active_record/journal/journable/context.rb', line 16 def add(action:, journable:, rule:) map = public_send(action) map[journable.model_name.to_s] ||= [] map[journable.model_name.to_s] << rule end |
#search_by(action:, subject: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_record/journal/journable/context.rb', line 22 def search_by(action:, subject: nil) map = public_send(action) return unless map return map.values.flatten if subject.nil? key = map.keys.find { |name| subject.is_a?(name.constantize) } return unless key map[key] end |