Module: Cyclid::API::Organizations::Stages::Helpers

Includes:
Errors::HTTPErrors
Defined in:
app/cyclid/controllers/organizations/stages.rb

Overview

Helpers for Stages

Instance Method Summary collapse

Instance Method Details

#create_steps(stage_steps) ⇒ Object

Create the serialized steps

For each definition in the payload, inspect it and create the appropriate object for that action; that class is then serialized into JSON and stored in the Step in the database, and can then be unserialized back in to the desired object when it’s needed without the database having to be aware of every single permutation of possible actions and arguments to them.



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'app/cyclid/controllers/organizations/stages.rb', line 221

def create_steps(stage_steps)
  sequence = 1
  stage_steps.map do |stage_step|
    step = Step.new
    step.sequence = sequence

    begin
      action_name = stage_step['action']
      plugin = Cyclid.plugins.find(action_name, Cyclid::API::Plugins::Action)

      step_action = plugin.new(stage_step)
      raise if step_action.nil?
    rescue StandardError => ex
      # XXX Rescue an internal exception
      halt_with_json_response(404, INVALID_ACTION, ex.message)
    end

    # Serialize the object into the Step and store it in the database.
    step.action = Oj.dump(step_action)
    step.save!

    sequence += 1

    step
  end
end