Class: EventMachine::StatHat
- Inherits:
-
Object
- Object
- EventMachine::StatHat
- Defined in:
- lib/em-stathat.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
Class Method Summary collapse
-
.config(&block) ⇒ Object
Configure EM::StatHat.
- .configured? ⇒ Boolean
Instance Method Summary collapse
- #config ⇒ Object
-
#ez_count(stat_name, count = 1) ⇒ Object
Increment a counter via the EZ api.
-
#ez_value(stat_name, value) ⇒ Object
Record a value via the EZ api.
-
#initialize(base_uri = 'http://api.stathat.com') ⇒ StatHat
constructor
A new instance of StatHat.
-
#time(name, opts = {}) ⇒ Object
Time a block of code and send the duration as a value.
Constructor Details
#initialize(base_uri = 'http://api.stathat.com') ⇒ StatHat
Returns a new instance of StatHat.
30 31 32 33 |
# File 'lib/em-stathat.rb', line 30 def initialize(base_uri = 'http://api.stathat.com') raise(RuntimeError, "You must configure EM::StatHat before using it!") unless self.class.configured? @base_uri = base_uri end |
Class Method Details
.config(&block) ⇒ Object
Configure EM::StatHat
17 18 19 20 21 22 23 |
# File 'lib/em-stathat.rb', line 17 def config(&block) if block_given? @@config.tap(&block) else @@config end end |
.configured? ⇒ Boolean
25 26 27 |
# File 'lib/em-stathat.rb', line 25 def configured? !!config.ukey && !!config.email end |
Instance Method Details
#config ⇒ Object
35 |
# File 'lib/em-stathat.rb', line 35 def config; self.class.config; end |
#ez_count(stat_name, count = 1) ⇒ Object
Increment a counter via the EZ api
66 67 68 |
# File 'lib/em-stathat.rb', line 66 def ez_count(stat_name, count = 1) ez(stat_name, {:count => count}) end |
#ez_value(stat_name, value) ⇒ Object
Record a value via the EZ api
61 62 63 |
# File 'lib/em-stathat.rb', line 61 def ez_value(stat_name, value) ez(stat_name, {:value => value}) end |
#time(name, opts = {}) ⇒ Object
Time a block of code and send the duration as a value
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/em-stathat.rb', line 47 def time(name, opts = {}) opts[:ez] ||= true start = Time.now yield if block_given? if opts[:ez] == true ez_value(name, (Time.now - start)) else value(name, (Time.now - start)) end end |