Class: TrailGuide::Metrics::Config

Inherits:
Canfig::Config
  • Object
show all
Defined in:
lib/trail_guide/metrics/config.rb

Constant Summary collapse

INHERIT_KEYS =
[ :allow_multiple_conversions, :allow_conversion, :on_convert ]
CALLBACK_KEYS =
[ :allow_conversion, :on_convert ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric, *args, **opts, &block) ⇒ Config

Returns a new instance of Config.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/trail_guide/metrics/config.rb', line 9

def initialize(metric, *args, **opts, &block)
  @metric = metric

  opts = INHERIT_KEYS.map do |key|
    val = experiment.configuration[key]
    val = val.dup if val
    [ key, val ]
  end.to_h.merge(opts)

  super(*args, **opts, &block)
end

Instance Attribute Details

#metricObject (readonly)

Returns the value of attribute metric.



4
5
6
# File 'lib/trail_guide/metrics/config.rb', line 4

def metric
  @metric
end

Instance Method Details

#allow_conversion(meth = nil, &block) ⇒ Object

TODO do we allow a method here? do we call it on the experiment?

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/trail_guide/metrics/config.rb', line 34

def allow_conversion(meth=nil, &block)
  raise ArgumentError if meth.nil? && !block_given?
  self[:allow_conversion] ||= []
  self[:allow_conversion] << (meth || block)
end

#allow_multiple_conversions?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/trail_guide/metrics/config.rb', line 29

def allow_multiple_conversions?
  !!allow_multiple_conversions
end

#callbacksObject



25
26
27
# File 'lib/trail_guide/metrics/config.rb', line 25

def callbacks
  to_h.slice(*CALLBACK_KEYS).map { |k,v| [k, [v].flatten.compact] }.to_h
end

#experimentObject



21
22
23
# File 'lib/trail_guide/metrics/config.rb', line 21

def experiment
  metric.experiment
end

#on_convert(meth = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/trail_guide/metrics/config.rb', line 40

def on_convert(meth=nil, &block)
  raise ArgumentError if meth.nil? && !block_given?
  self[:on_convert] ||= []
  self[:on_convert] << (meth || block)
end