Module: SnowAgent

Defined in:
lib/snowagent/railtie.rb,
lib/snowagent.rb,
lib/snowagent/agent.rb,
lib/snowagent/sender.rb,
lib/snowagent/service.rb,
lib/snowagent/version.rb,
lib/snowagent/configuration.rb,
lib/snowagent/sync_strategy.rb,
lib/snowagent/async_strategy.rb

Overview

This module loading only for Rails apps

Defined Under Namespace

Classes: Agent, AsyncStrategy, Configuration, Railtie, Sender, Service, SyncStrategy

Constant Summary collapse

VERSION =
"0.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.agentObject



31
32
33
# File 'lib/snowagent.rb', line 31

def agent
  @agent ||= Agent.new(configuration)
end

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

Yields:



56
57
58
59
60
# File 'lib/snowagent.rb', line 56

def configure
  yield(configuration)
  # do not trigger initialization if not configured
  self.agent if configuration.configured?
end

.increment(key, value = 1) ⇒ Object



52
53
54
# File 'lib/snowagent.rb', line 52

def increment(key, value = 1)
  metric(key, value, "counter")
end

.loggerObject



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

def logger
  @logger ||= Logger.new(STDOUT)
end

.metric(*args) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/snowagent.rb', line 35

def metric(*args)
  if configuration.configured?
    agent.metric(*args)
  else
    # logger.debug "Metric was not send due to configuration."
  end

  nil
end

.time(key) ⇒ Object



45
46
47
48
49
50
# File 'lib/snowagent.rb', line 45

def time(key)
  start = Time.now
  result = yield
  metric(key, ((Time.now - start) * 1000).round, "time")
  result
end