Class: Hoover::Job
- Inherits:
-
Object
- Object
- Hoover::Job
- Defined in:
- lib/hoover/job.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#logglier ⇒ Object
writeonly
Sets the attribute logglier.
Instance Method Summary collapse
- #add(hash) ⇒ Object
-
#initialize(logglier = nil) ⇒ Job
constructor
A new instance of Job.
- #post ⇒ Object
- #ready_to_post? ⇒ Boolean
Constructor Details
#initialize(logglier = nil) ⇒ Job
Returns a new instance of Job.
6 7 8 9 |
# File 'lib/hoover/job.rb', line 6 def initialize(logglier = nil) @logglier = logglier @hash = {} end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
4 5 6 |
# File 'lib/hoover/job.rb', line 4 def hash @hash end |
#logglier=(value) ⇒ Object (writeonly)
Sets the attribute logglier
3 4 5 |
# File 'lib/hoover/job.rb', line 3 def logglier=(value) @logglier = value end |
Instance Method Details
#add(hash) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/hoover/job.rb', line 11 def add(hash) sanitize(hash).each do |k,v| if @hash.key?(k) @hash[k] << v else @hash[k] = [v] end end end |
#post ⇒ Object
25 26 27 28 29 30 |
# File 'lib/hoover/job.rb', line 25 def post raise "cannot post until logglier is set" unless ready_to_post? @hash.each{ |k,v| @hash[k] = @hash[k].first if v.size == 1 } Rails.logger.info " Hoover sending keys #{@hash.keys.inspect} to Loggly" if defined?(Rails) && Rails.logger @logglier.info(@hash) end |
#ready_to_post? ⇒ Boolean
21 22 23 |
# File 'lib/hoover/job.rb', line 21 def ready_to_post? ! @logglier.nil? end |