Class: Cyclid::API::Job::StageView
- Inherits:
-
Object
- Object
- Cyclid::API::Job::StageView
- Defined in:
- app/cyclid/job/stage.rb
Overview
Non-AR model for Stages. Using a wrapper allows us to create an ad-hoc stage (I.e. one that is not stored in the database) or load a stage from the database and merge in over-rides without risking modifying the database object.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#not_if ⇒ Object
Returns the value of attribute not_if.
-
#on_failure ⇒ Object
Returns the value of attribute on_failure.
-
#on_success ⇒ Object
Returns the value of attribute on_success.
-
#only_if ⇒ Object
Returns the value of attribute only_if.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(arg) ⇒ StageView
constructor
A new instance of StageView.
Constructor Details
#initialize(arg) ⇒ StageView
Returns a new instance of StageView.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/cyclid/job/stage.rb', line 30 def initialize(arg) if arg.is_a? Cyclid::API::Stage @name = arg.name @version = arg.version @steps = arg.steps.map(&:serializable_hash) elsif arg.is_a? Hash arg.symbolize_keys! raise ArgumentError, 'name is required' unless arg.key? :name @name = arg[:name] @version = arg.fetch(:version, '1.0.0') # Create & serialize Actions for each step sequence = 1 @steps = arg[:steps].map do |step| Cyclid.logger.debug "ad-hoc step=#{step}" action_name = step['action'] plugin = Cyclid.plugins.find(action_name, Cyclid::API::Plugins::Action) step_action = plugin.new(step) raise ArgumentError if step_action.nil? # Serialize the object into the Step and store it in the database. action = Oj.dump(step_action) step_definition = { sequence: sequence, action: action } sequence += 1 step_definition end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'app/cyclid/job/stage.rb', line 27 def name @name end |
#not_if ⇒ Object
Returns the value of attribute not_if.
28 29 30 |
# File 'app/cyclid/job/stage.rb', line 28 def not_if @not_if end |
#on_failure ⇒ Object
Returns the value of attribute on_failure.
28 29 30 |
# File 'app/cyclid/job/stage.rb', line 28 def on_failure @on_failure end |
#on_success ⇒ Object
Returns the value of attribute on_success.
28 29 30 |
# File 'app/cyclid/job/stage.rb', line 28 def on_success @on_success end |
#only_if ⇒ Object
Returns the value of attribute only_if.
28 29 30 |
# File 'app/cyclid/job/stage.rb', line 28 def only_if @only_if end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
27 28 29 |
# File 'app/cyclid/job/stage.rb', line 27 def steps @steps end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
27 28 29 |
# File 'app/cyclid/job/stage.rb', line 27 def version @version end |