Module: Staccato::Measurable

Overview

Measurable adds field mapping and param collection

for Measurement classes to be add to Hit

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/staccato/measurable.rb', line 5

def self.included(model)
  model.extend Forwardable

  model.class_eval do
    attr_accessor :options

    def_delegators :@options, *model::FIELDS.keys
  end
end

Instance Method Details

#add_custom_dimension(dimension_index, value) ⇒ Object

Set a custom dimension value at an index

Parameters:

  • dimension_index (Integer)
  • value


49
50
51
52
# File 'lib/staccato/measurable.rb', line 49

def add_custom_dimension(dimension_index, value)
  return unless custom_fields_allowed?
  self.custom_dimensions["#{prefix}cd#{dimension_index}"] = value
end

#add_custom_metric(metric_index, value) ⇒ Object

Set a custom metric value at an index

Parameters:

  • metric_index (Integer)
  • value


63
64
65
66
# File 'lib/staccato/measurable.rb', line 63

def add_custom_metric(metric_index, value)
  return unless custom_fields_allowed?
  self.custom_metrics["#{prefix}cm#{metric_index}"] = value
end

#custom_dimensionsHash

Custom dimensions for this measurable

Returns:

  • (Hash)


56
57
58
# File 'lib/staccato/measurable.rb', line 56

def custom_dimensions
  @custom_dimensions ||= {}
end

#custom_fields_allowed?Boolean

not all measurements allow custom dimensions or metrics

Returns:

  • (Boolean)


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

def custom_fields_allowed?
  false
end

#custom_metricsHash

Custom metrics for this measurable

Returns:

  • (Hash)


70
71
72
# File 'lib/staccato/measurable.rb', line 70

def custom_metrics
  @custom_metrics ||= {}
end

#fieldsObject

fields from options for this measurement



21
22
23
# File 'lib/staccato/measurable.rb', line 21

def fields
  self.class::FIELDS
end

#initialize(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    options for the measurement fields



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

def initialize(options = {})
  self.options = OptionSet.new(options)
end

#paramsHash

collects the parameters from options for this measurement

Returns:

  • (Hash)


38
39
40
41
42
43
44
# File 'lib/staccato/measurable.rb', line 38

def params
  {}.
  merge!(measurable_params).
  merge!(custom_dimensions).
  merge!(custom_metrics).
  reject {|_,v| v.nil?}
end

#prefixString

measurement option prefix

Returns:

  • (String)


27
28
29
# File 'lib/staccato/measurable.rb', line 27

def prefix
  ''
end