Class: Audiences::Context

Inherits:
ApplicationRecord show all
Includes:
MembershipGroup
Defined in:
app/models/audiences/context.rb

Overview

Represents a context where the group of users (audience) is relevant. It includes the current matching users and the criteria to match these users (#criteria, #match_all, #extra_users).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(owner) ⇒ Audiences::Context

Finds or creates a context for the given owner

Returns:



25
26
27
# File 'app/models/audiences/context.rb', line 25

def self.for(owner)
  where(owner: owner).first_or_create!
end

Instance Method Details

#refresh_users!Object



29
30
31
32
33
# File 'app/models/audiences/context.rb', line 29

def refresh_users!
  criteria.each(&:refresh_users!)
  update!(users: ContextUsers.new(self).to_a)
  Notifications.publish(self)
end