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.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(name, arn = nil) ⇒ StateMachine
constructor
A new instance of StateMachine.
- #run(mock_data = {}, input = {}, test_name = nil) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, arn = nil) ⇒ StateMachine
30 31 32 33 34 |
# File 'lib/sfn/state_machine.rb', line 30 def initialize(name, arn = nil) self.name = name self.arn = arn || self.class.find_by_name(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 |
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'], 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
36 37 38 39 40 |
# File 'lib/sfn/state_machine.rb', line 36 def destroy AwsCli.run('stepfunctions', 'delete-state-machine', { 'state-machine-arn': arn }) Collection.instance.delete_by_arn(arn) end |
#run(mock_data = {}, input = {}, test_name = nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/sfn/state_machine.rb', line 42 def run(mock_data = {}, input = {}, test_name = nil) test_name ||= OpenSSL::Digest::SHA512.digest(mock_data.merge(input).to_json) executions[test_name] ||= Execution.call(self, test_name, mock_data, input) executions[test_name] end |
#to_hash ⇒ Object
48 49 50 |
# File 'lib/sfn/state_machine.rb', line 48 def to_hash { 'stateMachineArn' => arn, 'name' => name } end |