floe 0.11.3 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/floe/workflow.rb CHANGED
@@ -6,6 +6,7 @@ require "json"
6
6
  module Floe
7
7
  class Workflow
8
8
  include Logging
9
+ include ValidationMixin
9
10
 
10
11
  class << self
11
12
  def load(path_or_io, context = nil, credentials = {}, name = nil)
@@ -96,19 +97,21 @@ module Floe
96
97
  # caller should really put credentials into context and not pass that variable
97
98
  context.credentials = credentials if credentials
98
99
 
99
- raise Floe::InvalidWorkflowError, "Missing field \"States\"" if payload["States"].nil?
100
- raise Floe::InvalidWorkflowError, "Missing field \"StartAt\"" if payload["StartAt"].nil?
101
- raise Floe::InvalidWorkflowError, "\"StartAt\" not in the \"States\" field" unless payload["States"].key?(payload["StartAt"])
102
-
103
- @name = name
100
+ # NOTE: this is a string, and states use an array
101
+ @name = name || "State Machine"
104
102
  @payload = payload
105
103
  @context = context
106
104
  @comment = payload["Comment"]
107
105
  @start_at = payload["StartAt"]
108
106
 
109
- @states = payload["States"].to_a.map { |state_name, state| State.build!(self, state_name, state) }
110
- @states_by_name = @states.each_with_object({}) { |state, result| result[state.name] = state }
111
- rescue Floe::InvalidWorkflowError
107
+ # NOTE: Everywhere else we include our name (i.e.: parent name) when building the child name.
108
+ # When creating the states, we are dropping our name (i.e.: the workflow name)
109
+ @states = payload["States"].to_a.map { |state_name, state| State.build!(self, ["States", state_name], state) }
110
+
111
+ validate_workflow
112
+
113
+ @states_by_name = @states.each_with_object({}) { |state, result| result[state.short_name] = state }
114
+ rescue Floe::Error
112
115
  raise
113
116
  rescue => err
114
117
  raise Floe::InvalidWorkflowError, err.message
@@ -157,7 +160,7 @@ module Floe
157
160
  end
158
161
 
159
162
  def output
160
- context.output if end?
163
+ context.json_output if end?
161
164
  end
162
165
 
163
166
  def end?
@@ -187,8 +190,15 @@ module Floe
187
190
  def credentials
188
191
  @context.credentials
189
192
  end
193
+
190
194
  private
191
195
 
196
+ def validate_workflow
197
+ missing_field_error!("States") if @states.empty?
198
+ missing_field_error!("StartAt") if @start_at.nil?
199
+ invalid_field_error!("StartAt", @start_at, "is not found in \"States\"") unless workflow_state?(@start_at, self)
200
+ end
201
+
192
202
  def step!
193
203
  next_state = {"Name" => context.next_state, "Guid" => SecureRandom.uuid, "PreviousStateGuid" => context.state["Guid"]}
194
204
 
data/lib/floe.rb CHANGED
@@ -7,7 +7,9 @@ require_relative "floe/logging"
7
7
 
8
8
  require_relative "floe/runner"
9
9
 
10
+ require_relative "floe/validation_mixin"
10
11
  require_relative "floe/workflow"
12
+ require_relative "floe/workflow/error_matcher_mixin"
11
13
  require_relative "floe/workflow/catcher"
12
14
  require_relative "floe/workflow/choice_rule"
13
15
  require_relative "floe/workflow/choice_rule/not"
@@ -15,6 +17,9 @@ require_relative "floe/workflow/choice_rule/or"
15
17
  require_relative "floe/workflow/choice_rule/and"
16
18
  require_relative "floe/workflow/choice_rule/data"
17
19
  require_relative "floe/workflow/context"
20
+ require_relative "floe/workflow/intrinsic_function"
21
+ require_relative "floe/workflow/intrinsic_function/parser"
22
+ require_relative "floe/workflow/intrinsic_function/transformer"
18
23
  require_relative "floe/workflow/path"
19
24
  require_relative "floe/workflow/payload_template"
20
25
  require_relative "floe/workflow/reference_path"
@@ -37,6 +42,8 @@ require "time"
37
42
  module Floe
38
43
  class Error < StandardError; end
39
44
  class InvalidWorkflowError < Error; end
45
+ class InvalidExecutionInput < Error; end
46
+ class PathError < Error; end
40
47
 
41
48
  def self.logger
42
49
  @logger ||= NullLogger.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: floe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-20 00:00:00.000000000 Z
11
+ date: 2024-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_spawn
@@ -80,20 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: parslet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: manageiq-style
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: 1.5.2
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: 1.5.2
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +136,6 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: simplecov
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -196,6 +196,7 @@ files:
196
196
  - lib/floe/logging.rb
197
197
  - lib/floe/null_logger.rb
198
198
  - lib/floe/runner.rb
199
+ - lib/floe/validation_mixin.rb
199
200
  - lib/floe/version.rb
200
201
  - lib/floe/workflow.rb
201
202
  - lib/floe/workflow/catcher.rb
@@ -205,6 +206,10 @@ files:
205
206
  - lib/floe/workflow/choice_rule/not.rb
206
207
  - lib/floe/workflow/choice_rule/or.rb
207
208
  - lib/floe/workflow/context.rb
209
+ - lib/floe/workflow/error_matcher_mixin.rb
210
+ - lib/floe/workflow/intrinsic_function.rb
211
+ - lib/floe/workflow/intrinsic_function/parser.rb
212
+ - lib/floe/workflow/intrinsic_function/transformer.rb
208
213
  - lib/floe/workflow/path.rb
209
214
  - lib/floe/workflow/payload_template.rb
210
215
  - lib/floe/workflow/reference_path.rb