Class: Sfn::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/sfn/state_machine.rb

Constant Summary collapse

ROLE =
'arn:aws:iam::123456789012:role/DummyRole'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#arnObject

Returns the value of attribute arn.



12
13
14
# File 'lib/sfn/state_machine.rb', line 12

def arn
  @arn
end

#definitionObject

Returns the value of attribute definition.



12
13
14
# File 'lib/sfn/state_machine.rb', line 12

def definition
  @definition
end

#execution_arnObject

Returns the value of attribute execution_arn.



12
13
14
# File 'lib/sfn/state_machine.rb', line 12

def execution_arn
  @execution_arn
end

#executionsObject

Returns the value of attribute executions.



12
13
14
# File 'lib/sfn/state_machine.rb', line 12

def executions
  @executions
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/sfn/state_machine.rb', line 12

def name
  @name
end

Class Method Details

.allObject



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_allObject



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

#destroyObject



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_hashObject



48
49
50
# File 'lib/sfn/state_machine.rb', line 48

def to_hash
  { 'stateMachineArn' => arn, 'name' => name }
end