Class: Upkeep::Invalidation::CollectionRemove
- Inherits:
-
Object
- Object
- Upkeep::Invalidation::CollectionRemove
- Defined in:
- lib/upkeep/invalidation/collection_remove.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(recipe, change) ⇒ CollectionRemove
constructor
A new instance of CollectionRemove.
Constructor Details
#initialize(recipe, change) ⇒ CollectionRemove
Returns a new instance of CollectionRemove.
10 11 12 13 |
# File 'lib/upkeep/invalidation/collection_remove.rb', line 10 def initialize(recipe, change) @recipe = recipe @change = change end |
Class Method Details
.build(recipe:, change:) ⇒ Object
6 7 8 |
# File 'lib/upkeep/invalidation/collection_remove.rb', line 6 def self.build(recipe:, change:) new(recipe, change).build end |
Instance Method Details
#build ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/upkeep/invalidation/collection_remove.rb', line 15 def build replay = recipe.replay return unless replay.is_a?(Replay::Collection) return unless destroy_change? collection = replay.collection return unless collection.is_a?(Replay::ActiveRecordRelationValue) return unless collection.member_ids.map(&:to_s).include?(change.fetch(:id).to_s) model = constantize(collection.model) return unless change.fetch(:table) == model.table_name Replay::Recipe.new( kind: :render_site_remove, frame_id: recipe.frame_id, target_kind: "dom_id", target_id: dom_id(model, change.fetch(:id)), template: recipe.template, metadata: recipe., runtime: "rails", replay: Replay::Empty.new ) end |