class Blackbeard::Pirate
Public Class Methods
new()
click to toggle source
# File lib/blackbeard/pirate.rb, line 13 def initialize @metrics = {} @tests = {} @features = {} @cohorts = {} end
Public Instance Methods
ab_test(id, options)
click to toggle source
# File lib/blackbeard/pirate.rb, line 70 def ab_test(id, options) return self unless @set_context @set_context.ab_test(id, options) end
add_to_cohort(id, timestamp = nil)
click to toggle source
# File lib/blackbeard/pirate.rb, line 60 def add_to_cohort(id, timestamp = nil) return self unless @set_context @set_context.add_to_cohort(id, timestamp) end
add_to_cohort!(id, timestamp = nil)
click to toggle source
# File lib/blackbeard/pirate.rb, line 65 def add_to_cohort!(id, timestamp = nil) return self unless @set_context @set_context.add_to_cohort!(id, timestamp) end
add_total(id, amount)
click to toggle source
# 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)
click to toggle source
TODO: metaprogram all the context delegators
# File lib/blackbeard/pirate.rb, line 50 def add_unique(id) return self unless @set_context @set_context.add_unique(id) end
clear_context()
click to toggle source
# File lib/blackbeard/pirate.rb, line 45 def clear_context @set_context = nil end
cohort(id)
click to toggle source
# File lib/blackbeard/pirate.rb, line 29 def cohort(id) @cohorts[id] ||= Cohort.find_or_create(id) end
context(*args)
click to toggle source
# File lib/blackbeard/pirate.rb, line 37 def context(*args) Context.new(self, *args) end
feature(id)
click to toggle source
# File lib/blackbeard/pirate.rb, line 33 def feature(id) @features[id] ||= Feature.find_or_create(id) end
feature_active?(id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/blackbeard/pirate.rb, line 41 def set_context(*args) @set_context = context(*args) end
test(id)
click to toggle source
TODO: abstract out memoization to a cache class
# File lib/blackbeard/pirate.rb, line 25 def test(id) @tests[id] ||= Test.find_or_create(id) end