Module: Segmentation::ClassMethods

Defined in:
lib/has_metrics/segmentation.rb

Overview

CLASS METHODS ADDED

Instance Method Summary collapse

Instance Method Details

#segment_by(category, &definition) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/has_metrics/segmentation.rb', line 9

def segment_by category, &definition
  (@segment_categories ||= []) << category.to_sym
  define_method("segment_by_#{category}", definition)
  if respond_to?(:has_metric)
    has_metric "by_#{category}" do
      send("segment_by_#{category}")
    end
  end
end

#segment_categoriesObject



18
19
20
# File 'lib/has_metrics/segmentation.rb', line 18

def segment_categories
  @segment_categories
end

#update_segments!Object



21
22
23
24
25
26
27
28
# File 'lib/has_metrics/segmentation.rb', line 21

def update_segments!
  puts "Updating all segments on #{name}: #{segment_categories.join(', ')}"
  all.each do |object|
    segment_categories.each do |category|
      object.update_segment!(category)
    end
  end
end