Class: Hoover::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/hoover/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hashObject (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

Parameters:

  • value

    the value to set the attribute logglier to.



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

#postObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/hoover/job.rb', line 21

def ready_to_post?
  ! @logglier.nil?
end