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

#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)


33
34
35
36
37
38
39
40
41
42
# File 'lib/staccato/measurable.rb', line 33

def params
  Hash[
    fields.map { |field,key|
      next if key.nil?
      key = (prefix+key.to_s)

      [key, options[field]] unless options[field].nil?
    }.compact
  ]
end

#prefixString

measurement option prefix

Returns:

  • (String)


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

def prefix
  ''
end