states-dsl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ module States
2
+ module Dsl
3
+ class StateMachine < ExecutionContext
4
+ attr_reader :states
5
+
6
+ def initialize(options)
7
+ super(nil, options)
8
+ end
9
+
10
+ def trait(name, options={}, &block)
11
+ trait = Trait.new(options, context)
12
+ trait.instance_eval(&block)
13
+ @context.register_trait(name, trait)
14
+ end
15
+
16
+ def comment(comment)
17
+ @comment = comment
18
+ end
19
+
20
+ def serializable_hash
21
+ h = super
22
+ h["Comment"] = @comment if @comment
23
+ h
24
+ end
25
+
26
+ def to_json
27
+ JSON.pretty_generate(serializable_hash)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module States
2
+ module Dsl
3
+ class StateName
4
+ attr_reader :local_name
5
+ attr_accessor :index
6
+
7
+ def initialize(local_name, naming)
8
+ @local_name = local_name
9
+ @naming = naming
10
+ end
11
+
12
+ def to_s
13
+ @naming.resolve
14
+ resolved = local_name.to_s
15
+ unless index.nil?
16
+ resolved += "_#{(index + 1)}"
17
+ end
18
+ @naming.convert(resolved)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module States
2
+ module Dsl
3
+
4
+ class StateReference
5
+ attr_accessor :resolved_to
6
+ attr_reader :name
7
+
8
+ def initialize(name, naming)
9
+ @name = name
10
+ @naming = naming
11
+ end
12
+
13
+ def to_s
14
+ @resolved_to.to_s
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module States
2
+ module Dsl
3
+ class Trait < StateLike
4
+ def initialize(options, context)
5
+ super(options)
6
+ self.context = context
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module States
2
+ module Dsl
3
+ class VariableChoice < Choice
4
+ include VariableCondition
5
+
6
+ def initialize(path, naming)
7
+ super(naming)
8
+ @variable = path
9
+ end
10
+
11
+ def serializable_hash
12
+ super.merge("Variable" => @variable).merge(condition_hash)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,59 @@
1
+ module States
2
+ module Dsl
3
+ module VariableCondition
4
+ checks = {
5
+ string_equals: "StringEquals",
6
+ string_less_than: "StringLessThan",
7
+ string_greater_than: "StringGreaterThan",
8
+ string_less_than_equals: "StringLessThanEquals",
9
+ string_greater_than_equals: "StringGreaterThanEquals",
10
+
11
+ string_eq: "StringEquals",
12
+ string_lt: "StringLessThan",
13
+ string_gt: "StringGreaterThan",
14
+ string_lte: "StringLessThanEquals",
15
+ string_gte: "StringGreaterThanEquals",
16
+
17
+ numeric_equals: "NumericEquals",
18
+ numeric_less_than: "NumericLessThan",
19
+ numeric_greater_than: "NumericGreaterThan",
20
+ numeric_less_than_equals: "NumericLessThanEquals",
21
+ numeric_greater_than_equals: "NumericGreaterThanEquals",
22
+
23
+ numeric_eq: "NumericEquals",
24
+ numeric_lt: "NumericLessThan",
25
+ numeric_gt: "NumericGreaterThan",
26
+ numeric_lte: "NumericLessThanEquals",
27
+ numeric_gte: "NumericGreaterThanEquals",
28
+
29
+ boolean_equals: "BooleanEquals",
30
+
31
+ timestamp_equals: "TimestampEquals",
32
+ timestamp_less_than: "TimestampLessThan",
33
+ timestamp_greater_than: "TimestampGreaterThan",
34
+ timestamp_less_than_equals: "TimestampLessThanEquals",
35
+ timestamp_greater_than_equals: "TimestampGreaterThanEquals",
36
+
37
+ timestamp_eq: "TimestampEquals",
38
+ timestamp_lt: "TimestampLessThan",
39
+ timestamp_gt: "TimestampGreaterThan",
40
+ timestamp_lte: "TimestampLessThanEquals",
41
+ timestamp_gte: "TimestampGreaterThanEquals",
42
+ }
43
+
44
+ checks.keys.each do |name|
45
+ define_method name do |val|
46
+ instance_variable_set("@#{name}".to_sym, val)
47
+ end
48
+ end
49
+
50
+ define_method :condition_hash do
51
+ h = {}
52
+ if k = checks.keys.detect { |nm| !instance_variable_get("@#{nm}".to_sym).nil? }
53
+ h[checks[k]] = instance_variable_get("@#{k}".to_sym)
54
+ end
55
+ h
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ module States
2
+ module Dsl
3
+ class VariableConditionPart
4
+ include VariableCondition
5
+
6
+ def initialize(path)
7
+ @variable = path
8
+ end
9
+
10
+ def serializable_hash
11
+ { "Variable" => @variable }.merge(condition_hash)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module States
2
+ module Dsl
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module States
2
+ module Dsl
3
+ class Wait
4
+ def initialize(options={})
5
+ end
6
+
7
+ def seconds(seconds)
8
+ @seconds = seconds
9
+ end
10
+
11
+ def seconds_path(path)
12
+ @seconds_path = path
13
+ end
14
+
15
+ def timestamp(ts)
16
+ @timestamp = ts
17
+ end
18
+
19
+ def timestamp_path(path)
20
+ @timestamp_path = path
21
+ end
22
+
23
+ def serializable_hash
24
+ h = {}
25
+ if @seconds
26
+ h["Seconds"] = @seconds
27
+ elsif @seconds_path
28
+ h["SecondsPath"] = @seconds_path
29
+ elsif @timestamp
30
+ h["Timestamp"] = @timestamp
31
+ elsif @timestamp_path
32
+ h["TimestampPath"] = @timestamp_path
33
+ end
34
+ h
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "states/dsl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "states-dsl"
8
+ spec.version = States::Dsl::VERSION
9
+ spec.authors = ["Calvin Yu"]
10
+ spec.email = ["calvin@rylabs.io"]
11
+
12
+ spec.summary = %q{Create AWS Step Function JSON from a DSL}
13
+ spec.description = %q{Create AWS Step Function JSON from a DSL}
14
+ spec.homepage = "http://github.com/rylabs/states-dsl"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = ["states-dsl"]
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "thor"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: states-dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Calvin Yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Create AWS Step Function JSON from a DSL
70
+ email:
71
+ - calvin@rylabs.io
72
+ executables:
73
+ - states-dsl
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - bin/states-dsl
88
+ - examples/simple.rb
89
+ - lib/states/dsl.rb
90
+ - lib/states/dsl/catch.rb
91
+ - lib/states/dsl/choice.rb
92
+ - lib/states/dsl/choices.rb
93
+ - lib/states/dsl/cli.rb
94
+ - lib/states/dsl/condition_group.rb
95
+ - lib/states/dsl/context.rb
96
+ - lib/states/dsl/error_support.rb
97
+ - lib/states/dsl/execution_context.rb
98
+ - lib/states/dsl/fail.rb
99
+ - lib/states/dsl/namespace.rb
100
+ - lib/states/dsl/naming.rb
101
+ - lib/states/dsl/parallel.rb
102
+ - lib/states/dsl/resource_lookup.rb
103
+ - lib/states/dsl/retry.rb
104
+ - lib/states/dsl/state.rb
105
+ - lib/states/dsl/state_like.rb
106
+ - lib/states/dsl/state_machine.rb
107
+ - lib/states/dsl/state_name.rb
108
+ - lib/states/dsl/state_reference.rb
109
+ - lib/states/dsl/trait.rb
110
+ - lib/states/dsl/variable_choice.rb
111
+ - lib/states/dsl/variable_condition.rb
112
+ - lib/states/dsl/variable_condition_part.rb
113
+ - lib/states/dsl/version.rb
114
+ - lib/states/dsl/wait.rb
115
+ - states-dsl.gemspec
116
+ homepage: http://github.com/rylabs/states-dsl
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.6.11
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Create AWS Step Function JSON from a DSL
140
+ test_files: []