Class: Sfn::StateMachine
- Inherits:
-
Object
- Object
- Sfn::StateMachine
- Defined in:
- lib/sfn/state_machine.rb
Constant Summary collapse
- ROLE =
'arn:aws:iam::123456789012:role/DummyRole'
Instance Attribute Summary collapse
-
#arn ⇒ Object
Returns the value of attribute arn.
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#execution_arn ⇒ Object
Returns the value of attribute execution_arn.
-
#executions ⇒ Object
Returns the value of attribute executions.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#variables ⇒ Object
Returns the value of attribute variables.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #dry_run(mock_data = {}, input = {}, test_name = nil) ⇒ Object
-
#initialize(name, variables = {}, arn = nil) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #run(mock_data = {}, input = {}, test_name = nil, dry_run = false) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, variables = {}, arn = nil) ⇒ StateMachine
Returns a new instance of StateMachine.
30 31 32 33 34 35 36 |
# File 'lib/sfn/state_machine.rb', line 30 def initialize(name, variables = {}, arn = nil) self.path = "#{Sfn.configuration.definition_path}/#{name}.json" self.name = name.gsub('/','-') self.variables = (variables || {}).stringify_keys self.arn = arn || self.class.find_by_name(self.name)&.arn || create_state_machine self.executions = {} end |
Instance Attribute Details
#arn ⇒ Object
Returns the value of attribute arn.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def arn @arn end |
#definition ⇒ Object
Returns the value of attribute definition.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def definition @definition end |
#execution_arn ⇒ Object
Returns the value of attribute execution_arn.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def execution_arn @execution_arn end |
#executions ⇒ Object
Returns the value of attribute executions.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def executions @executions end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def path @path end |
#variables ⇒ Object
Returns the value of attribute variables.
12 13 14 |
# File 'lib/sfn/state_machine.rb', line 12 def variables @variables end |
Class Method Details
.all ⇒ Object
14 15 16 |
# File 'lib/sfn/state_machine.rb', line 14 def self.all Collection.instance.all.map { |sf| new(sf['name'], nil, sf['stateMachineArn']) } end |
.destroy_all ⇒ Object
18 19 20 |
# File 'lib/sfn/state_machine.rb', line 18 def self.destroy_all all.each(&:destroy) end |
.find_by_arn(arn) ⇒ Object
26 27 28 |
# File 'lib/sfn/state_machine.rb', line 26 def self.find_by_arn(arn) all.find { |sf| sf.arn == arn } end |
.find_by_name(name) ⇒ Object
22 23 24 |
# File 'lib/sfn/state_machine.rb', line 22 def self.find_by_name(name) all.find { |sf| sf.name == name } end |
Instance Method Details
#destroy ⇒ Object
38 39 40 41 42 |
# File 'lib/sfn/state_machine.rb', line 38 def destroy AwsCli.run('stepfunctions', 'delete-state-machine', { 'state-machine-arn': arn }) Collection.instance.delete_by_arn(arn) end |
#dry_run(mock_data = {}, input = {}, test_name = nil) ⇒ Object
44 45 46 |
# File 'lib/sfn/state_machine.rb', line 44 def dry_run(mock_data = {}, input = {}, test_name = nil) execution = run(mock_data, input, test_name, true) end |
#run(mock_data = {}, input = {}, test_name = nil, dry_run = false) ⇒ Object
48 49 50 51 52 |
# File 'lib/sfn/state_machine.rb', line 48 def run(mock_data = {}, input = {}, test_name = nil, dry_run = false) test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge({ input: input }).to_json) executions[test_name] ||= Execution.call(self, test_name, mock_data, input, dry_run) executions[test_name] end |
#to_hash ⇒ Object
54 55 56 |
# File 'lib/sfn/state_machine.rb', line 54 def to_hash { 'stateMachineArn' => arn, 'name' => name } end |