Class: Raes::Reducer
Instance Method Summary collapse
- #call ⇒ Object
- #create_state ⇒ Object
-
#initialize(action) ⇒ Reducer
constructor
A new instance of Reducer.
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
#call ⇒ Object
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_state ⇒ Object
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 |