Class: RubyNos::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_nos/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ Processor

Returns a new instance of Processor.



6
7
8
# File 'lib/ruby_nos/processor.rb', line 6

def initialize agent
  @agent = agent
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



4
5
6
# File 'lib/ruby_nos/processor.rb', line 4

def agent
  @agent
end

#current_messageObject

Returns the value of attribute current_message.



4
5
6
# File 'lib/ruby_nos/processor.rb', line 4

def current_message
  @current_message
end

Instance Method Details

#formatterObject



10
11
12
# File 'lib/ruby_nos/processor.rb', line 10

def formatter
  @formatter ||= Formatter.new
end

#process_message(received_message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_nos/processor.rb', line 18

def process_message received_message
  formatted_message = formatter.parse_message(received_message)
  self.current_message = Message.new(formatted_message)

  unless sender_uuid == agent.uuid || !correct_signature?(formatted_message)
    RubyNos.logger.send(:info, "#{self.current_message.type} arrives")
    if agent_receptor? || cloud_receptor?
      processor = message_processor.fetch(current_message.type, nil)
      processor.call if processor
    end
  end
end

#signature_generatorObject



14
15
16
# File 'lib/ruby_nos/processor.rb', line 14

def signature_generator
  @signature_generator ||= SignatureGenerator.new
end