simplerubysteps 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,274 +1,3 @@
1
1
  require "simplerubysteps/version"
2
- require "json"
3
-
4
- module Simplerubysteps
5
- # Step Functions JSON generator
6
-
7
- $FUNCTION_ARN = ENV["LAMBDA_FUNCTION_ARN"] ? ENV["LAMBDA_FUNCTION_ARN"] : "unknown"
8
-
9
- def function_name
10
- return "unknown" unless $FUNCTION_ARN =~ /.+\:function\:(.+)/
11
- $1
12
- end
13
-
14
- class StateMachine
15
- attr_reader :states
16
- attr_reader :start_at
17
- attr_accessor :kind
18
-
19
- def initialize()
20
- @states = {}
21
- @kind = "STANDARD"
22
- end
23
-
24
- def add(state)
25
- @start_at = state.name unless @start_at
26
-
27
- @states[state.name] = state
28
- state.state_machine = self
29
-
30
- state
31
- end
32
-
33
- def render
34
- {
35
- :StartAt => @start_at,
36
- :States => @states.map { |name, state| [name, state.render] }.to_h,
37
- }
38
- end
39
- end
40
-
41
- class State
42
- attr_reader :name
43
- attr_accessor :state_machine
44
-
45
- def initialize(name)
46
- @name = name
47
- @dict = {}
48
- end
49
-
50
- def []=(key, value)
51
- @dict[key] = value
52
- end
53
-
54
- def next=(state)
55
- @dict[:Next] = (state.is_a? Symbol) ? state : state.name
56
- end
57
-
58
- def render
59
- dict = @dict
60
- dict[:End] = true unless dict[:Next]
61
- dict
62
- end
63
- end
64
-
65
- class Task < State
66
- def initialize(name)
67
- super
68
- @dict[:Type] = "Task"
69
- @dict[:Resource] = $FUNCTION_ARN
70
- @dict[:Parameters] = {
71
- :Task => name,
72
- "Input.$" => "$",
73
- }
74
- end
75
-
76
- def action(&action_block)
77
- @action_block = action_block
78
- end
79
-
80
- def perform_action(input)
81
- output = nil
82
- output = @action_block.call(input) if @action_block
83
-
84
- if @implicit_choice
85
- output = {} unless output
86
- @implicit_choice.perform_action(output)
87
- end
88
-
89
- output
90
- end
91
-
92
- def implicit_choice
93
- unless @implicit_choice
94
- @implicit_choice = Choice.new("#{name}_choice")
95
- $sm.add @implicit_choice
96
- self.next = @implicit_choice
97
- end
98
- @implicit_choice
99
- end
100
- end
101
-
102
- class Callback < State
103
- def initialize(name)
104
- super
105
- @dict[:Type] = "Task"
106
- @dict[:Resource] = "arn:aws:states:::lambda:invoke.waitForTaskToken"
107
- @dict[:Parameters] = {
108
- :FunctionName => function_name,
109
- :Payload => {
110
- :Task => name,
111
- "Input.$" => "$",
112
- "Token.$" => "$$.Task.Token",
113
- },
114
- }
115
- end
116
-
117
- def action(&action_block)
118
- @action_block = action_block
119
- end
120
-
121
- def perform_action(input, token)
122
- @action_block.call(input, token) if @action_block
123
- end
124
- end
125
-
126
- class ChoiceItem
127
- attr_accessor :implicit_condition_block
128
-
129
- def initialize(dict = {}, state = nil)
130
- @dict = dict
131
- self.next = state if state
132
- end
133
-
134
- def next=(state)
135
- @dict[:Next] = (state.is_a? Symbol) ? state : state.name
136
- end
137
-
138
- def render
139
- @dict
140
- end
141
-
142
- def perform_action(choice_name, output)
143
- if @implicit_condition_block
144
- output["#{choice_name}_#{@dict[:Next]}"] = @implicit_condition_block.call(output) ? "yes" : "no"
145
- end
146
- end
147
- end
148
-
149
- class Choice < State
150
- attr_reader :choices
151
-
152
- def initialize(name)
153
- super
154
- @choices = []
155
- @dict[:Type] = "Choice"
156
- end
157
-
158
- def add(item)
159
- @choices.push item
160
- end
161
-
162
- def add_string_matches(var, match, state)
163
- add ChoiceItem.new({
164
- :Variable => var,
165
- :StringMatches => match,
166
- }, state)
167
- end
168
-
169
- def default=(state)
170
- @dict[:Default] = (state.is_a? Symbol) ? state : state.name
171
- end
172
-
173
- def next=(state)
174
- self.default = state
175
- end
176
-
177
- def render
178
- dict = @dict.clone
179
- dict[:Choices] = @choices.map { |item| item.render }
180
- dict
181
- end
182
-
183
- def perform_action(output)
184
- @choices.each do |choice|
185
- choice.perform_action name, output
186
- end
187
- end
188
- end
189
-
190
- # Workflow DSL
191
-
192
- $sm = StateMachine.new
193
- $tasks = []
194
-
195
- def kind(k)
196
- $sm.kind = k
197
- end
198
-
199
- def task(name)
200
- t = $sm.add Task.new(name)
201
-
202
- $tasks.last.next = t if $tasks.last
203
-
204
- $tasks.push t
205
- yield if block_given?
206
- $tasks.pop
207
- end
208
-
209
- def callback(name)
210
- t = $sm.add Callback.new(name)
211
-
212
- $tasks.last.next = t if $tasks.last
213
-
214
- $tasks.push t
215
- yield if block_given?
216
- $tasks.pop
217
- end
218
-
219
- def action(&action_block)
220
- $tasks.last.action &action_block
221
- end
222
-
223
- def transition(state)
224
- $tasks.last.next = state
225
- end
226
-
227
- def transition_to(state, &condition_block)
228
- choice = $tasks.last.implicit_choice
229
-
230
- c = ChoiceItem.new({
231
- :Variable => "$.#{choice.name}_#{state}",
232
- :StringMatches => "yes",
233
- })
234
- c.next = state
235
- c.implicit_condition_block = condition_block
236
-
237
- choice.add c
238
- end
239
-
240
- def default_transition_to(state)
241
- choice = $tasks.last.implicit_choice
242
-
243
- choice.default = state
244
- end
245
-
246
- def choice(name)
247
- t = $sm.add Choice.new(name)
248
-
249
- $tasks.last.next = t if $tasks.last
250
-
251
- $tasks.push t
252
- yield if block_given?
253
- $tasks.pop
254
- end
255
-
256
- def string_matches(var, match)
257
- c = ChoiceItem.new({
258
- :Variable => var,
259
- :StringMatches => match,
260
- })
261
-
262
- $tasks.last.add c
263
-
264
- $tasks.push c
265
- yield if block_given?
266
- $tasks.pop
267
- end
268
-
269
- def default
270
- $tasks.push $tasks.last
271
- yield if block_given?
272
- $tasks.pop
273
- end
274
- end
2
+ require "simplerubysteps/model"
3
+ require "simplerubysteps/dsl"
@@ -8,14 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Christian Tschenett"]
9
9
  spec.email = ["simplerubysteps@furthermore.ch"]
10
10
 
11
- spec.summary = %q{simplerubysteps makes it easy to manage AWS Step Functions with ruby (eventually - this is an early alpha version and should not really be used by everyone).}
11
+ spec.summary = %q{simplerubysteps makes it easy to manage AWS Step Functions with ruby (this is an early alpha version and should not really be used by anyone).}
12
12
 
13
13
  spec.homepage = "https://github.com/chtz/simplerubysteps"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- end
16
+ spec.files = Dir.glob("lib/**/*.rb") + %w[exe/simplerubysteps exe/srs README.md Rakefile simplerubysteps.gemspec]
19
17
 
20
18
  spec.bindir = "exe"
21
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplerubysteps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Tschenett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-15 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,27 +113,21 @@ email:
113
113
  - simplerubysteps@furthermore.ch
114
114
  executables:
115
115
  - simplerubysteps
116
+ - srs
116
117
  extensions: []
117
118
  extra_rdoc_files: []
118
119
  files:
119
- - ".gitignore"
120
- - Gemfile
121
- - LICENSE.txt
122
120
  - README.md
123
121
  - Rakefile
124
- - bin/console
125
- - bin/setup
126
122
  - exe/simplerubysteps
123
+ - exe/srs
127
124
  - lib/function.rb
128
125
  - lib/simplerubysteps.rb
126
+ - lib/simplerubysteps/cloudformation.rb
127
+ - lib/simplerubysteps/dsl.rb
128
+ - lib/simplerubysteps/model.rb
129
+ - lib/simplerubysteps/tool.rb
129
130
  - lib/simplerubysteps/version.rb
130
- - lib/statemachine.yaml
131
- - lib/tool.rb
132
- - samples/sample1/sample-task-worker.sh
133
- - samples/sample1/start-callbackbranch.sh
134
- - samples/sample1/start-directbranch.sh
135
- - samples/sample1/workflow.rb
136
- - samples/sample2/workflow.rb
137
131
  - simplerubysteps.gemspec
138
132
  homepage: https://github.com/chtz/simplerubysteps
139
133
  licenses:
@@ -157,6 +151,6 @@ requirements: []
157
151
  rubygems_version: 3.0.3.1
158
152
  signing_key:
159
153
  specification_version: 4
160
- summary: simplerubysteps makes it easy to manage AWS Step Functions with ruby (eventually
161
- - this is an early alpha version and should not really be used by everyone).
154
+ summary: simplerubysteps makes it easy to manage AWS Step Functions with ruby (this
155
+ is an early alpha version and should not really be used by anyone).
162
156
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- Gemfile.lock
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 Christian Tschenett
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/bin/console DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "simplerubysteps"
5
-
6
- require "irb"
7
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install