Class: HiddenHippo::Updator

Inherits:
Object
  • Object
show all
Defined in:
lib/hidden_hippo/updator.rb

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Updator

Returns a new instance of Updator.



6
7
8
# File 'lib/hidden_hippo/updator.rb', line 6

def initialize(queue)
  @queue = queue
end

Instance Method Details

#startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hidden_hippo/updator.rb', line 10

def start
  return if @thread
  @thread = Thread.new do
    loop do
      update = @queue.pop

      break if update == :stop

      dossier = dossier update.mac_address

      update.fields.each do |key, value|
        dossier.public_send(key) << value
      end

      begin
      dossier.save
      rescue => e
        puts 'shit'
        p e
      end
    end
  end
end

#stopObject



34
35
36
37
# File 'lib/hidden_hippo/updator.rb', line 34

def stop
  @queue << :stop
  @thread.join
end