Module: Caffeinate::Dripper::Campaign::ClassMethods

Defined in:
lib/caffeinate/dripper/campaign.rb

Instance Method Summary collapse

Instance Method Details

#caffeinate_campaignObject Also known as: campaign

Returns the ‘Caffeinate::Campaign` object for the Dripper.

If ‘config.implicit_campaigns` is true, this will automatically create a `Caffeinate::Campaign` if one is not found via the `campaign_slug`.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/caffeinate/dripper/campaign.rb', line 41

def caffeinate_campaign
  return @caffeinate_campaign if @caffeinate_campaign.present?

  if ::Caffeinate.config.implicit_campaigns?
    @caffeinate_campaign = ::Caffeinate::Campaign.find_or_initialize_by(slug: campaign_slug)
    if @caffeinate_campaign.new_record?
      @caffeinate_campaign.name = "#{name.delete_suffix('Dripper').titleize} Campaign"
      @caffeinate_campaign.save!
    end
  else
    @caffeinate_campaign = ::Caffeinate::Campaign[campaign_slug]
  end

  @caffeinate_campaign
end

#campaign=(slug) ⇒ Object

Sets the campaign on the Dripper and resets any existing ‘@caffeinate_campaign`

class OrdersDripper < ApplicationDripper
  campaign :order_drip
end

If this is not explicitly set, we will infer it with

self.name.delete_suffix("Campaign").underscore

Parameters:

  • slug (Symbol)

    The slug of a persisted ‘Caffeinate::Campaign`.



31
32
33
34
35
# File 'lib/caffeinate/dripper/campaign.rb', line 31

def campaign=(slug)
  @caffeinate_campaign = nil
  @_campaign_slug = slug.to_sym
  Caffeinate.dripper_collection.register(@_campaign_slug, name)
end

#campaign_slugObject

The defined slug or the inferred slug



59
60
61
# File 'lib/caffeinate/dripper/campaign.rb', line 59

def campaign_slug
  @_campaign_slug || inferred_campaign_slug
end