Class: Workarea::Segment

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document::Taggable, ApplicationDocument, Commentable
Defined in:
app/models/workarea/segment.rb,
app/models/workarea/segment/life_cycle.rb,
app/models/workarea/segment/rules/base.rb,
app/models/workarea/segment/rules/tags.rb,
app/models/workarea/segment/rules/orders.rb,
app/models/workarea/segment/rules/revenue.rb,
app/models/workarea/segment/loyal_customer.rb,
app/models/workarea/segment/rules/sessions.rb,
app/models/workarea/segment/rules/logged_in.rb,
app/models/workarea/segment/rules/last_order.rb,
app/models/workarea/segment/returning_visitor.rb,
app/models/workarea/segment/rules/geolocation.rb,
app/models/workarea/segment/first_time_visitor.rb,
app/models/workarea/segment/returning_customer.rb,
app/models/workarea/segment/rules/browser_info.rb,
app/models/workarea/segment/first_time_customer.rb,
app/models/workarea/segment/rules/traffic_referrer.rb,
app/models/workarea/segment/rules/geolocation_option.rb

Defined Under Namespace

Modules: LifeCycle, Rules Classes: FirstTimeCustomer, FirstTimeVisitor, LoyalCustomer, ReturningCustomer, ReturningVisitor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mongoid::Document::Taggable

included

Methods included from Commentable

#add_subscription, #remove_subscription

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.currentObject



21
22
23
# File 'app/models/workarea/segment.rb', line 21

def self.current
  Thread.current[:current_segments] || []
end

.current=(*segments) ⇒ Object



25
26
27
# File 'app/models/workarea/segment.rb', line 25

def self.current=(*segments)
  Thread.current[:current_segments] = Array.wrap(segments).flatten
end

.enabledObject



33
34
35
36
37
38
# File 'app/models/workarea/segment.rb', line 33

def self.enabled
  Thread.current[:enable_segmentation] = true
  yield
ensure
  Thread.current[:enable_segmentation] = nil
end

.enabled?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/workarea/segment.rb', line 29

def self.enabled?
  !!Thread.current[:enable_segmentation]
end

.find_qualifying(visit) ⇒ Object



17
18
19
# File 'app/models/workarea/segment.rb', line 17

def self.find_qualifying(visit)
  all.select { |s| s.qualifies?(visit) }
end

.with_current(*segments) ⇒ Object



40
41
42
43
44
45
46
47
# File 'app/models/workarea/segment.rb', line 40

def self.with_current(*segments)
  previous = current

  self.current = segments
  enabled { yield }
ensure
  self.current = previous
end

Instance Method Details

#qualifies?(visit) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'app/models/workarea/segment.rb', line 49

def qualifies?(visit)
  return false if visit.blank?
  rules.all? { |r| r.qualifies?(visit) }
end