Class: Raes::Dispatch

Inherits:
Object
  • Object
show all
Includes:
UseCaller
Defined in:
lib/raes/dispatch.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, payload = {}) ⇒ Dispatch

Returns a new instance of Dispatch.



7
8
9
10
# File 'lib/raes/dispatch.rb', line 7

def initialize(name, payload = {})
  @action = Action.create(name: name)
  @payload = payload
end

Instance Method Details

#callObject



12
13
14
15
16
# File 'lib/raes/dispatch.rb', line 12

def call
  @action.payload = create_payload.to_json
  SubscribeJob.perform_later(@action) if @action.save
  @action
end

#create_payloadObject



18
19
20
21
22
23
24
25
# File 'lib/raes/dispatch.rb', line 18

def create_payload
  if @payload[:raes_storage].present?
    storage = @action.storages.create(name: @action.name, content: @payload[:raes_storage])
    @payload.delete(:raes_storage)
    @payload[:raes_storage_id] = storage.id
  end
  @payload
end