Class: TrailGuide::Metrics::Config
- Inherits:
-
Canfig::Config
- Object
- Canfig::Config
- TrailGuide::Metrics::Config
- 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
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
Instance Method Summary collapse
-
#allow_conversion(meth = nil, &block) ⇒ Object
TODO do we allow a method here? do we call it on the experiment?.
- #allow_multiple_conversions? ⇒ Boolean
- #callbacks ⇒ Object
- #experiment ⇒ Object
-
#initialize(metric, *args, **opts, &block) ⇒ Config
constructor
A new instance of Config.
- #on_convert(meth = nil, &block) ⇒ Object
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
#metric ⇒ Object (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?
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
29 30 31 |
# File 'lib/trail_guide/metrics/config.rb', line 29 def allow_multiple_conversions? !!allow_multiple_conversions end |
#callbacks ⇒ Object
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 |
#experiment ⇒ Object
21 22 23 |
# File 'lib/trail_guide/metrics/config.rb', line 21 def experiment metric.experiment end |
#on_convert(meth = nil, &block) ⇒ Object
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 |