Class: Uglier::Client
- Inherits:
-
Object
- Object
- Uglier::Client
- Defined in:
- lib/uglier/client.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ :host => '127.0.0.1', :port => '8124', :flags => 0, :namespace => '', :namespace_delimeter => '.', }
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #flush_queue ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #log(data) ⇒ Object
- #namespace_prefix ⇒ Object
- #queue(data) ⇒ Object
- #reset_queue ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 |
# File 'lib/uglier/client.rb', line 17 def initialize(config = {}) @config = DEFAULT_CONFIG.merge(config) reset_queue end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/uglier/client.rb', line 15 def config @config end |
Instance Method Details
#flush_queue ⇒ Object
43 44 45 46 |
# File 'lib/uglier/client.rb', line 43 def flush_queue log(@queue) reset_queue end |
#log(data) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/uglier/client.rb', line 22 def log(data) return if data.size == 0 # no data is being logged # Add namespace prefix, if it exists if (ns_prefix = namespace_prefix).size > 0 data = data.inject({}) do |memo, (k, v)| memo[ns_prefix + k.to_s] = v memo end end socket.send(data.to_json, @config[:flags], @config[:host], @config[:port]) end |
#namespace_prefix ⇒ Object
52 53 54 55 |
# File 'lib/uglier/client.rb', line 52 def namespace_prefix ns = @config[:namespace].to_s ns.size > 0 ? (ns + @config[:namespace_delimeter].to_s) : '' end |
#queue(data) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/uglier/client.rb', line 36 def queue(data) data.each do |k, v| @queue[k] ||= [] @queue[k].concat(v.is_a?(Array) ? v : [v]) end end |
#reset_queue ⇒ Object
48 49 50 |
# File 'lib/uglier/client.rb', line 48 def reset_queue @queue = {} end |