Class: Blackbeard::Pirate
- Inherits:
-
Object
- Object
- Blackbeard::Pirate
- Defined in:
- lib/blackbeard/pirate.rb
Instance Method Summary collapse
- #ab_test(id, options) ⇒ Object
- #add_to_cohort(id, timestamp = nil) ⇒ Object
- #add_to_cohort!(id, timestamp = nil) ⇒ Object
- #add_total(id, amount) ⇒ Object
-
#add_unique(id) ⇒ Object
TODO: metaprogram all the context delegators.
- #clear_context ⇒ Object
- #cohort(id) ⇒ Object
- #context(*args) ⇒ Object
- #feature(id) ⇒ Object
- #feature_active?(id) ⇒ Boolean
-
#initialize ⇒ Pirate
constructor
A new instance of Pirate.
- #metric(type, type_id) ⇒ Object
- #set_context(*args) ⇒ Object
-
#test(id) ⇒ Object
TODO: abstract out memoization to a cache class.
Constructor Details
#initialize ⇒ Pirate
Returns a new instance of Pirate.
13 14 15 16 17 18 |
# File 'lib/blackbeard/pirate.rb', line 13 def initialize @metrics = {} @tests = {} @features = {} @cohorts = {} end |
Instance Method Details
#ab_test(id, options) ⇒ Object
70 71 72 73 |
# File 'lib/blackbeard/pirate.rb', line 70 def ab_test(id, ) return self unless @set_context @set_context.ab_test(id, ) end |
#add_to_cohort(id, timestamp = nil) ⇒ Object
60 61 62 63 |
# File 'lib/blackbeard/pirate.rb', line 60 def add_to_cohort(id, = nil) return self unless @set_context @set_context.add_to_cohort(id, ) end |
#add_to_cohort!(id, timestamp = nil) ⇒ Object
65 66 67 68 |
# File 'lib/blackbeard/pirate.rb', line 65 def add_to_cohort!(id, = nil) return self unless @set_context @set_context.add_to_cohort!(id, ) end |
#add_total(id, amount) ⇒ Object
55 56 57 58 |
# File 'lib/blackbeard/pirate.rb', line 55 def add_total(id, amount) return self unless @set_context @set_context.add_total(id, amount) end |
#add_unique(id) ⇒ Object
TODO: metaprogram all the context delegators
50 51 52 53 |
# File 'lib/blackbeard/pirate.rb', line 50 def add_unique(id) return self unless @set_context @set_context.add_unique(id) end |
#clear_context ⇒ Object
45 46 47 |
# File 'lib/blackbeard/pirate.rb', line 45 def clear_context @set_context = nil end |
#cohort(id) ⇒ Object
29 30 31 |
# File 'lib/blackbeard/pirate.rb', line 29 def cohort(id) @cohorts[id] ||= Cohort.find_or_create(id) end |
#context(*args) ⇒ Object
37 38 39 |
# File 'lib/blackbeard/pirate.rb', line 37 def context(*args) Context.new(self, *args) end |
#feature(id) ⇒ Object
33 34 35 |
# File 'lib/blackbeard/pirate.rb', line 33 def feature(id) @features[id] ||= Feature.find_or_create(id) end |
#feature_active?(id) ⇒ Boolean
75 76 77 78 |
# File 'lib/blackbeard/pirate.rb', line 75 def feature_active?(id) return false unless @set_context @set_context.feature_active?(id) end |
#metric(type, type_id) ⇒ Object
20 21 22 |
# File 'lib/blackbeard/pirate.rb', line 20 def metric(type, type_id) @metrics["#{type}::#{type_id}"] ||= Metric.find_or_create(type, type_id) end |
#set_context(*args) ⇒ Object
41 42 43 |
# File 'lib/blackbeard/pirate.rb', line 41 def set_context(*args) @set_context = context(*args) end |
#test(id) ⇒ Object
TODO: abstract out memoization to a cache class
25 26 27 |
# File 'lib/blackbeard/pirate.rb', line 25 def test(id) @tests[id] ||= Test.find_or_create(id) end |