Class: Collavre::Creatives::PlanTagger
- Inherits:
-
Object
- Object
- Collavre::Creatives::PlanTagger
- Defined in:
- app/services/collavre/creatives/plan_tagger.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(plan_id:, creative_ids: [], user: nil) ⇒ PlanTagger
constructor
A new instance of PlanTagger.
- #remove ⇒ Object
Constructor Details
#initialize(plan_id:, creative_ids: [], user: nil) ⇒ PlanTagger
Returns a new instance of PlanTagger.
6 7 8 9 10 |
# File 'app/services/collavre/creatives/plan_tagger.rb', line 6 def initialize(plan_id:, creative_ids: [], user: nil) @plan = Plan.find_by(id: plan_id) @creative_ids = Array(creative_ids).map(&:presence).compact @user = user end |
Instance Method Details
#apply ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/services/collavre/creatives/plan_tagger.rb', line 12 def apply return failure("Please select a plan and at least one creative.") unless valid? creatives.find_each do |creative| creative..find_or_create_by(label: plan, creative_id: creative.id) end success("Plan tags applied to selected creatives.") end |
#remove ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/collavre/creatives/plan_tagger.rb', line 22 def remove return failure("Please select a plan and at least one creative.") unless valid? creatives.find_each do |creative| tag = creative..find_by(label: plan, creative_id: creative.id) tag&.destroy end success("Plan tag removed from selected creatives.") end |