Class: Untied::Consumer::Sync::PayloadProccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/untied-consumer-sync/payload_proccessor.rb

Constant Summary collapse

@@instances =

Public: Traduz payload recebido via Untied de acordo com os atributos e mapeamentos do config/model_data.yml.

{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_data) ⇒ PayloadProccessor

Returns a new instance of PayloadProccessor.



10
11
12
# File 'lib/untied-consumer-sync/payload_proccessor.rb', line 10

def initialize(model_data)
  @model_data = model_data
end

Class Method Details

.new(*args, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/untied-consumer-sync/payload_proccessor.rb', line 32

def self.new(*args, &block)
  old_instance = @@instances[args[0]['name']]
  return old_instance if old_instance

  obj = PayloadProccessor.allocate
  obj.send(:initialize, *args, &block)
  @@instances[args[0]['name']] = obj
  obj
end

Instance Method Details

#dependenciesObject

Public: Metódo de conveniencia para checar as dependencias

Retorna um Array com as dependencias presentes na configuração do modelo



28
29
30
# File 'lib/untied-consumer-sync/payload_proccessor.rb', line 28

def dependencies
  @model_data.fetch('check_for', [])
end

#proccess(payload) ⇒ Object

Public: Faz o processamento geral da payload

payload - Hash com os dados do modelo

Retorna um novo Hash com os dados processados



19
20
21
22
23
# File 'lib/untied-consumer-sync/payload_proccessor.rb', line 19

def proccess(payload)
  new_payload = slice_useless_attrs(payload)

  map_attrs(new_payload)
end