Class: Raes::Reducer

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

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ Reducer

Returns a new instance of Reducer.



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

def initialize(action)
  @action = action
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/raes/reducer.rb', line 11

def call
  return @action unless @action.queued!

  @action.working!
  @action.state = create_state.to_json
  @action.status = :completed
rescue StandardError => e
  @action.state = { message: e }
  @action.status = :failed
ensure
  @action.save!
  @action
end

#create_stateObject



25
26
27
28
29
30
31
# File 'lib/raes/reducer.rb', line 25

def create_state
  if @action.name.constantize.method(:call).arity.zero?
    @action.name.constantize.call
  else
    @action.name.constantize.call(JSON.parse(@action.payload).symbolize_keys)
  end
end