Module: Meerstats

Defined in:
lib/meerstats.rb,
lib/meerstats/engine.rb,
lib/meerstats/runner.rb,
lib/meerstats/version.rb,
lib/meerstats/installer.rb,
lib/meerstats/lazy_metric.rb,
lib/meerstats/configuration.rb,
app/controllers/meerstats/api_controller.rb,
app/controllers/meerstats/api/metrics_controller.rb,
app/controllers/meerstats/api/statistics_controller.rb,
app/controllers/meerstats/api/health_check_controller.rb

Defined Under Namespace

Classes: ApiController, Configuration, Engine, Installer, LazyMetric, Runner

Constant Summary collapse

VERSION =
'1.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



11
12
13
# File 'lib/meerstats.rb', line 11

def self.configuration
  @configuration ||= Configuration.new
end

Class Method Details

.add(name, scope:, type: 'daily') ⇒ Object



31
32
33
34
35
36
37
# File 'lib/meerstats.rb', line 31

def self.add(name, scope:, type: 'daily')
  if metric = metrics.find { |m| m.name == name }
    metric.scope = scope
  else
    metrics << LazyMetric.new(name, scope: scope, type: type)
  end
end

.add_cumulative(name, scope) ⇒ Object



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

def self.add_cumulative(name, scope)
  add(name, scope: scope, type: 'cumulative')
end

.add_daily(name, scope) ⇒ Object



23
24
25
# File 'lib/meerstats.rb', line 23

def self.add_daily(name, scope)
  add(name, scope: scope, type: 'daily')
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/meerstats.rb', line 15

def self.configure
  yield(configuration)
end

.metricsObject



19
20
21
# File 'lib/meerstats.rb', line 19

def self.metrics
  @metrics ||= []
end

.statistics_for(name, days_ago: 1) ⇒ Object



39
40
41
42
43
44
# File 'lib/meerstats.rb', line 39

def self.statistics_for(name, days_ago: 1)
  metric = metrics.find { |m| m.name == name.to_sym }
  metric.compute(days_ago: days_ago)
rescue
  nil
end