Module: Ablab::ModuleMethods

Included in:
Ablab
Defined in:
lib/ablab.rb

Constant Summary collapse

TRACKING_EXCEPTION_HANDLER =
Proc.new { |e| raise e }
ALLOW_TRACKING =
Proc.new { true }

Instance Method Summary collapse

Instance Method Details

#allow_tracking(&block) ⇒ Object



52
53
54
55
# File 'lib/ablab.rb', line 52

def allow_tracking(&block)
  @allow_tracking = block if block_given?
  @allow_tracking || ALLOW_TRACKING
end

#callbacksObject



65
66
67
# File 'lib/ablab.rb', line 65

def callbacks
  @callbacks || []
end

#dashboard_credentials(credentials = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ablab.rb', line 38

def dashboard_credentials(credentials = nil)
  if credentials
    unless credentials[:name] && credentials[:password]
      raise InvalidCredentials, 'credentials should provide name and password'
    end
    @dashboard_credentials = credentials
  end
  @dashboard_credentials
end

#experiment(name, &block) ⇒ Object



20
21
22
23
# File 'lib/ablab.rb', line 20

def experiment(name, &block)
  @experiments ||= {}
  @experiments[name] = Experiment.new(name, &block)
end

#experimentsObject



12
13
14
# File 'lib/ablab.rb', line 12

def experiments
  @experiments ||= {}
end

#on_track(&block) ⇒ Object



48
49
50
# File 'lib/ablab.rb', line 48

def on_track(&block)
  (@callbacks ||= []) << block
end

#on_tracking_exception(&block) ⇒ Object



57
58
59
# File 'lib/ablab.rb', line 57

def on_tracking_exception(&block)
  @tracking_exception_handler = block
end

#setup(&block) ⇒ Object



16
17
18
# File 'lib/ablab.rb', line 16

def setup(&block)
  instance_exec(&block)
end

#store(type, *args) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/ablab.rb', line 25

def store(type, *args)
  if type.is_a? Class
    @tracker = Class.new(*args)
  else
    class_name = type.to_s.split('_').map(&:capitalize).join
    @tracker = Ablab::Store.const_get(class_name).new(*args)
  end
end

#trackerObject



34
35
36
# File 'lib/ablab.rb', line 34

def tracker
  @tracker ||= Ablab::Store::Memory.new
end

#tracking_exception_handlerObject



61
62
63
# File 'lib/ablab.rb', line 61

def tracking_exception_handler
  @tracking_exception_handler || TRACKING_EXCEPTION_HANDLER
end