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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#experimentsObject (readonly)

Returns the value of attribute experiments.



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

def experiments
  @experiments
end

Instance Method Details

#allow_tracking(&block) ⇒ Object



50
51
52
53
# File 'lib/ablab.rb', line 50

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

#callbacksObject



63
64
65
# File 'lib/ablab.rb', line 63

def callbacks
  @callbacks || []
end

#dashboard_credentials(credentials = nil) ⇒ Object



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

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



18
19
20
21
# File 'lib/ablab.rb', line 18

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

#on_track(&block) ⇒ Object



46
47
48
# File 'lib/ablab.rb', line 46

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

#on_tracking_exception(&block) ⇒ Object



55
56
57
# File 'lib/ablab.rb', line 55

def on_tracking_exception(&block)
  @tracking_exception_handler = block
end

#setup(&block) ⇒ Object



14
15
16
# File 'lib/ablab.rb', line 14

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

#store(type, *args) ⇒ Object



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

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



32
33
34
# File 'lib/ablab.rb', line 32

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

#tracking_exception_handlerObject



59
60
61
# File 'lib/ablab.rb', line 59

def tracking_exception_handler
  @tracking_exception_handler || TRACKING_EXCEPTION_HANDLER
end