Class: Marketing::Audiences::Target

Inherits:
Object
  • Object
show all
Defined in:
app/services/marketing/audiences/target.rb

Overview

Adapts an ad-synced Audience (the model — formerly Audience) into the
platform-neutral shape the adapters consume: a stable key, a display name,
target platforms, and a consent-gated Customer scope resolved from the
audience's saved advanced-search query (dynamic) or its members
(customer). Named Target, not Audience, to avoid colliding with the
::Audience model it wraps.

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audience) ⇒ Target

Returns a new instance of Target.

Parameters:



16
17
18
# File 'app/services/marketing/audiences/target.rb', line 16

def initialize(audience)
  @audience = audience
end

Class Method Details

.allArray<Target>

Returns one per Audience flagged for ad sync.

Returns:

  • (Array<Target>)

    one per Audience flagged for ad sync.



13
# File 'app/services/marketing/audiences/target.rb', line 13

def self.all = Audience.ad_synced.map { |audience| new(audience) }

Instance Method Details

#customer_scopeObject

Consent-gated Customer relation = the membership. Opt-outs are excluded
here, which is also how snapshot (OpenAI) removal happens. Memoized so an
audience syncing to N platforms resolves its query once.



32
33
34
# File 'app/services/marketing/audiences/target.rb', line 32

def customer_scope
  @customer_scope ||= Customer.where(id: member_customer_ids).consent_not_opted_out
end

#keyObject

Stable per-audience key — keys the Google user-list row and the OpenAI
audience name so re-syncs hit the same remote audience.



22
# File 'app/services/marketing/audiences/target.rb', line 22

def key = "audience-#{@audience.id}"

#nameObject

Alias for @audience#name

Returns:

  • (Object)

    @audience#name

See Also:



24
# File 'app/services/marketing/audiences/target.rb', line 24

delegate :name, to: :@audience

#platformsArray<String>

Returns platform keys (adapter labels) to sync to.

Returns:

  • (Array<String>)

    platform keys (adapter labels) to sync to.



27
# File 'app/services/marketing/audiences/target.rb', line 27

def platforms = Array(@audience.ad_platforms)