isomorfeus-operation 1.0.0.zeta25 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f493f5d6297ed16dc1330bb3a13ec2bea2f0271f13a486c5c257dbf970d1eba5
4
- data.tar.gz: 3ed6eac19f4175f0750f346e8c7c66002abf968215f6f4299d9b81cc8681a49b
3
+ metadata.gz: 4c8ee92e4d498d186f2efe71ac5ce933ab8258e93c2512ff42cc69aa5a70f949
4
+ data.tar.gz: db26b6e78ae73e822ab43e230a400461fef123433fb2c806390c5f4ad8136e69
5
5
  SHA512:
6
- metadata.gz: 5a4bd5b414bda10030812a0be6a6b44f570435c4e9088446f164584e119b7e6d206c1574959ee62ce85e41cdae21b0fc10783213e1e51a6fdb0248a4a6212589
7
- data.tar.gz: 9712d4272e5f2cf06f58f3fd87630ec49a9716f1f84d5f99ae5da069e6e28019886bd7d73eed8bc1d7bd674e76f2826a5eec204505f2eecf3d2b7bf54833a9b0
6
+ metadata.gz: 45a84974dcf579cc63675ae093059bf6c232ebdc3c28c4bb915a532813d62576fc56f3f2c3f54b20a144b612a8f1f854cc3604502f6c40c932ebcc390b87737c
7
+ data.tar.gz: d3884cfae5a8c39bc2bd52562715309c22457e5a554744f0717687612ca42ca97403022c94dd729a4ff04b7d5a1aff138f9bd45e543a4833a6647e2628eb34bb
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Jan Biedermann
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 all
13
- 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 THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jan Biedermann
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
- # isomorfeus-operation
2
-
3
- Operations for Isomorfeus.
4
-
5
- ### Community and Support
6
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
-
8
- ### Usage
9
- Operations use Props like other parts of the system.
10
- See [the isomorfeus-react props documentation](https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/props.md#prop-declaration).
11
-
12
- There are 3 kinds of Operations:
13
- - [LucidQuickOp](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/quick_op.md) - Quick simple operation, always executed on the server.
14
- - [LucidOperation](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/operation.md) - For complex multi-stepped operations, always executed on the server.
15
- - [LucidLocalOperation](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/operation.md) - For complex multi-stepped operations, always executed locally.
16
-
1
+ # isomorfeus-operation
2
+
3
+ Operations for Isomorfeus.
4
+
5
+ ### Community and Support
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
+
8
+ ### Usage
9
+ Operations use Props like other parts of the system.
10
+ See [the isomorfeus-preact props documentation](https://github.com/isomorfeus/isomorfeus-preact/blob/master/ruby/docs/props.md#prop-declaration).
11
+
12
+ There are 3 kinds of Operations:
13
+ - [LucidQuickOp](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/quick_op.md) - Quick simple operation, always executed on the server.
14
+ - [LucidOperation](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/operation.md) - For complex multi-stepped operations, always executed on the server.
15
+ - [LucidLocalOperation](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-operation/docs/operation.md) - For complex multi-stepped operations, always executed locally.
16
+
@@ -1,29 +1,29 @@
1
- module Isomorfeus
2
- class << self
3
- def cached_operation_classes
4
- @cached_operation_classes ||= {}
5
- end
6
-
7
- def cached_operation_class(class_name)
8
- return "::#{class_name}".constantize if Isomorfeus.development?
9
- return cached_operation_classes[class_name] if cached_operation_classes.key?(class_name)
10
- cached_operation_classes[class_name] = "::#{class_name}".constantize
11
- end
12
-
13
- if RUBY_ENGINE != 'opal'
14
- def valid_operation_class_names
15
- @valid_operation_class_names ||= Set.new
16
- end
17
-
18
- def valid_operation_class_name?(class_name)
19
- valid_operation_class_names.include?(class_name)
20
- end
21
-
22
- def add_valid_operation_class(klass)
23
- class_name = klass.name
24
- class_name = class_name.split('>::').last if class_name.start_with?('#<')
25
- valid_operation_class_names << class_name
26
- end
27
- end
28
- end
29
- end
1
+ module Isomorfeus
2
+ class << self
3
+ def cached_operation_classes
4
+ @cached_operation_classes ||= {}
5
+ end
6
+
7
+ def cached_operation_class(class_name)
8
+ return "::#{class_name}".constantize if Isomorfeus.development?
9
+ return cached_operation_classes[class_name] if cached_operation_classes.key?(class_name)
10
+ cached_operation_classes[class_name] = "::#{class_name}".constantize
11
+ end
12
+
13
+ if RUBY_ENGINE != 'opal'
14
+ def valid_operation_class_names
15
+ @valid_operation_class_names ||= Set.new
16
+ end
17
+
18
+ def valid_operation_class_name?(class_name)
19
+ valid_operation_class_names.include?(class_name)
20
+ end
21
+
22
+ def add_valid_operation_class(klass)
23
+ class_name = klass.name
24
+ class_name = class_name.split('>::').last if class_name.start_with?('#<')
25
+ valid_operation_class_names << class_name
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,65 +1,65 @@
1
- # frozen_string_literal: true
2
-
3
- module Isomorfeus
4
- module Operation
5
- module Handler
6
- class OperationHandler < LucidHandler::Base
7
- on_request do |response_agent|
8
- # promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.to_s, props_hash)
9
- response_agent.request.each_key do |operation_class_name|
10
- if Isomorfeus.valid_operation_class_name?(operation_class_name)
11
- operation_class = Isomorfeus.cached_operation_class(operation_class_name)
12
- if operation_class
13
- props = response_agent.request[operation_class_name]
14
- props.transform_keys!(&:to_sym)
15
- begin
16
- if Isomorfeus.current_user.authorized?(operation_class, :promise_run, props)
17
- operation_promise = operation_class.promise_run(**props)
18
- if operation_promise.realized?
19
- state = operation_promise.resolved? ? :resolved : :rejected
20
- result_hash = { state => operation_promise.value }
21
- if operation_promise.error
22
- e = operation_promise.error
23
- result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
24
- end
25
- response_agent.agent_result = { success: 'ok' , result: result_hash }
26
- else
27
- start = Time.now
28
- timeout = false
29
- while !operation_promise.realized?
30
- if (Time.now - start) > 20
31
- timeout = true
32
- break
33
- end
34
- sleep 0.01
35
- end
36
- if timeout
37
- response_agent.error = { error: 'Timeout' }
38
- else
39
- state = operation_promise.resolved? ? :resolved : :rejected
40
- result_hash = { state => operation_promise.value }
41
- if operation_promise.error
42
- e = operation_promise.error
43
- result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
44
- end
45
- response_agent.agent_result = { success: 'ok' , result: result_hash }
46
- end
47
- end
48
- else
49
- response_agent.error = { error: 'Access denied!' }
50
- end
51
- rescue Exception => e
52
- response_agent.error = { error: { operation_class_name => "Isomorfeus::Operation::Handler::OperationHandler: #{e.message}" }}
53
- end
54
- else
55
- response_agent.error = { error: { operation_class_name => 'Could not get operation class!' }}
56
- end
57
- else
58
- response_agent.error = { error: { operation_class_name => 'No such operation class!' }}
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Isomorfeus
4
+ module Operation
5
+ module Handler
6
+ class OperationHandler < LucidHandler::Base
7
+ on_request do |response_agent|
8
+ # promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.to_s, props_hash)
9
+ response_agent.request.each_key do |operation_class_name|
10
+ if Isomorfeus.valid_operation_class_name?(operation_class_name)
11
+ operation_class = Isomorfeus.cached_operation_class(operation_class_name)
12
+ if operation_class
13
+ props = response_agent.request[operation_class_name]
14
+ props.transform_keys!(&:to_sym)
15
+ begin
16
+ if Isomorfeus.current_user.authorized?(operation_class, :promise_run, props)
17
+ operation_promise = operation_class.promise_run(**props)
18
+ if operation_promise.realized?
19
+ state = operation_promise.resolved? ? :resolved : :rejected
20
+ result_hash = { state => operation_promise.value }
21
+ if operation_promise.error
22
+ e = operation_promise.error
23
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
24
+ end
25
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
26
+ else
27
+ start = Time.now
28
+ timeout = false
29
+ while !operation_promise.realized?
30
+ if (Time.now - start) > 20
31
+ timeout = true
32
+ break
33
+ end
34
+ sleep 0.01
35
+ end
36
+ if timeout
37
+ response_agent.error = { error: 'Timeout' }
38
+ else
39
+ state = operation_promise.resolved? ? :resolved : :rejected
40
+ result_hash = { state => operation_promise.value }
41
+ if operation_promise.error
42
+ e = operation_promise.error
43
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
44
+ end
45
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
46
+ end
47
+ end
48
+ else
49
+ response_agent.error = { error: 'Access denied!' }
50
+ end
51
+ rescue Exception => e
52
+ response_agent.error = { error: { operation_class_name => "Isomorfeus::Operation::Handler::OperationHandler: #{e.message}" }}
53
+ end
54
+ else
55
+ response_agent.error = { error: { operation_class_name => 'Could not get operation class!' }}
56
+ end
57
+ else
58
+ response_agent.error = { error: { operation_class_name => 'No such operation class!' }}
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
- module Isomorfeus
2
- module Operation
3
- VERSION = '1.0.0.zeta25'
4
- end
5
- end
1
+ module Isomorfeus
2
+ module Operation
3
+ VERSION = '2.0.0.rc4'
4
+ end
5
+ end
@@ -1,27 +1,29 @@
1
- require 'isomorfeus-transport'
2
- require 'isomorfeus/operation/config'
3
-
4
- if RUBY_ENGINE == 'opal'
5
- Isomorfeus.zeitwerk.push_dir('isomorfeus_operation')
6
- require_tree 'isomorfeus_operation', :autoload
7
- Isomorfeus.zeitwerk.push_dir('operations')
8
- else
9
- require 'oj'
10
- require 'isomorfeus/operation/handler/operation_handler'
11
- require 'isomorfeus_operation/lucid_operation/gherkin'
12
- require 'isomorfeus_operation/lucid_operation/steps'
13
- require 'isomorfeus_operation/lucid_operation/promise_run'
14
- require 'isomorfeus_operation/lucid_local_operation/mixin'
15
- require 'isomorfeus_operation/lucid_local_operation/base'
16
- require 'isomorfeus_operation/lucid_quick_op/mixin'
17
- require 'isomorfeus_operation/lucid_quick_op/base'
18
- require 'isomorfeus_operation/lucid_operation/mixin'
19
- require 'isomorfeus_operation/lucid_operation/base'
20
- Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
21
-
22
- # require 'active_support/dependencies'
23
-
24
- path = File.expand_path(File.join('app', 'operations'))
25
-
26
- Isomorfeus.zeitwerk.push_dir(path)
27
- end
1
+ require 'isomorfeus-transport'
2
+ require 'isomorfeus/operation/config'
3
+
4
+ if RUBY_ENGINE == 'opal'
5
+ Isomorfeus.zeitwerk.push_dir('isomorfeus_operation')
6
+ require_tree 'isomorfeus_operation', autoload: true
7
+ Isomorfeus.zeitwerk.push_dir('operations')
8
+ else
9
+ require 'oj'
10
+ require 'isomorfeus/operation/handler/operation_handler'
11
+ require 'isomorfeus_operation/lucid_operation/gherkin'
12
+ require 'isomorfeus_operation/lucid_operation/steps'
13
+ require 'isomorfeus_operation/lucid_operation/promise_run'
14
+ require 'isomorfeus_operation/lucid_local_operation/mixin'
15
+ require 'isomorfeus_operation/lucid_local_operation/base'
16
+ require 'isomorfeus_operation/lucid_quick_op/mixin'
17
+ require 'isomorfeus_operation/lucid_quick_op/base'
18
+ require 'isomorfeus_operation/lucid_operation/mixin'
19
+ require 'isomorfeus_operation/lucid_operation/base'
20
+
21
+ require 'iso_opal'
22
+ Opal.append_path(__dir__.untaint) unless IsoOpal.paths.include?(__dir__.untaint)
23
+
24
+ # require 'active_support/dependencies'
25
+
26
+ path = File.expand_path(File.join('app', 'operations'))
27
+
28
+ Isomorfeus.zeitwerk.push_dir(path)
29
+ end
@@ -1,11 +1,10 @@
1
- module LucidLocalOperation
2
- class Base
3
- include LucidLocalOperation::Mixin
4
-
5
- if RUBY_ENGINE != 'opal'
6
- def self.inherited(base)
7
- Isomorfeus.add_valid_operation_class(base)
8
- end
9
- end
10
- end
1
+ module LucidLocalOperation
2
+ class Base
3
+ def self.inherited(base)
4
+ base.include LucidLocalOperation::Mixin
5
+ if RUBY_ENGINE != 'opal'
6
+ Isomorfeus.add_valid_operation_class(base)
7
+ end
8
+ end
9
+ end
11
10
  end
@@ -1,35 +1,35 @@
1
- module LucidLocalOperation
2
- module Mixin
3
- def self.included(base)
4
- if RUBY_ENGINE != 'opal'
5
- Isomorfeus.add_valid_operation_class(base) unless base == LucidLocalOperation::Base
6
-
7
- def pub_sub_client
8
- Isomorfeus.pub_sub_client
9
- end
10
- end
11
-
12
- base.extend(LucidPropDeclaration::Mixin)
13
- base.extend(LucidOperation::Steps)
14
- base.include(LucidOperation::PromiseRun)
15
-
16
- base.instance_exec do
17
- def promise_run(**props_hash)
18
- self.new(**props_hash).promise_run
19
- end
20
- end
21
- end
22
-
23
- attr_reader :props
24
- attr_accessor :step_result
25
-
26
- def initialize(**props_hash)
27
- props_hash = self.class.validated_props(props_hash)
28
- @props = LucidProps.new(props_hash)
29
- end
30
-
31
- def current_user
32
- Isomorfeus.current_user
33
- end
34
- end
35
- end
1
+ module LucidLocalOperation
2
+ module Mixin
3
+ def self.included(base)
4
+ if RUBY_ENGINE != 'opal'
5
+ Isomorfeus.add_valid_operation_class(base) unless base == LucidLocalOperation::Base
6
+
7
+ def pub_sub_client
8
+ Isomorfeus.pub_sub_client
9
+ end
10
+ end
11
+
12
+ base.extend(LucidPropDeclaration::Mixin)
13
+ base.extend(LucidOperation::Steps)
14
+ base.include(LucidOperation::PromiseRun)
15
+
16
+ base.instance_exec do
17
+ def promise_run(**props_hash)
18
+ self.new(**props_hash).promise_run
19
+ end
20
+ end
21
+ end
22
+
23
+ attr_reader :props
24
+ attr_accessor :step_result
25
+
26
+ def initialize(**props_hash)
27
+ props_hash = self.class.validated_props(props_hash)
28
+ @props = LucidProps.new(props_hash)
29
+ end
30
+
31
+ def current_user
32
+ Isomorfeus.current_user
33
+ end
34
+ end
35
+ end
@@ -1,11 +1,10 @@
1
- module LucidOperation
2
- class Base
3
- include LucidOperation::Mixin
4
-
5
- if RUBY_ENGINE != 'opal'
6
- def self.inherited(base)
7
- Isomorfeus.add_valid_operation_class(base)
8
- end
9
- end
10
- end
11
- end
1
+ module LucidOperation
2
+ class Base
3
+ def self.inherited(base)
4
+ base.include LucidOperation::Mixin
5
+ if RUBY_ENGINE != 'opal'
6
+ Isomorfeus.add_valid_operation_class(base)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,63 +1,63 @@
1
- module LucidOperation
2
- module Gherkin
3
- FIRST_EXCEPTION = "First must be the first one that is used and can only used once!"
4
- FINALLY_EXCEPTION = "Finally, except for Ensure and Failed, must be the last one to be used and can only be used once!"
5
-
6
- NEWLINE = /\r?\n/
7
- OPERATION = /^\s*Operation: (.*)$/
8
- PROCEDURE = /^\s*Procedure: (.*)$/
9
- STAR = /^\s*\* (.*)$/
10
- GIVEN = /^\s*Given (.*)$/
11
- WHEN = /^\s*When (.*)$/
12
- THEN = /^\s*Then (.*)$/
13
- AND = /^\s*And (.*)$/
14
- FIRST = /^\s*First (.*)$/
15
- ENSURE = /^\s*Ensure (.*)$/
16
- FINALLY = /^\s*Finally (.*)$/
17
- IW_FAILING = /^\s*(?:When|If) failing (.*)$/
18
- IF_ITT_FAILED = /^\s*If (?:that|this|it) failed (.*)$/
19
- FAILED = /^\s*Failed (.*)$/
20
- COMMENT = /^\s*# (.*)$/
21
- WHITE_SPACE = /^\s*$/
22
-
23
- def self.parse(gherkin_text)
24
- operation = { operation: '', procedure: '', steps: [], failure: [], ensure: [] }
25
- has_finally = false
26
- lines = gherkin_text.split(NEWLINE)
27
-
28
- lines.each do |line|
29
- case line
30
- when STAR, GIVEN, WHEN, THEN, AND
31
- Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
32
- operation[:steps] << $1.strip
33
- when ENSURE
34
- operation[:ensure] << $1.strip
35
- when IW_FAILING, IF_ITT_FAILED, FAILED
36
- operation[:failure] << $1.strip
37
- when FIRST
38
- Isomorfeus.raise_error(message: FIRST_EXCEPTION) if operation[:steps].size > 0
39
- operation[:steps] << $1.strip
40
- when FINALLY
41
- Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
42
- operation[:steps] << $1.strip
43
- has_finally = true
44
- when PROCEDURE
45
- Isomorfeus.raise_error(message: 'No Operation defined!') if operation[:operation].empty?
46
- Isomorfeus.raise_error(message: 'Procedure already defined!') unless operation[:procedure].empty?
47
- operation[:procedure] = $1.strip
48
- when OPERATION
49
- Isomorfeus.raise_error(message: 'Operation already defined!') unless operation[:operation].empty?
50
- operation[:operation] = $1.strip
51
- when WHITE_SPACE, COMMENT
52
- # nothing, just skip
53
- else
54
- Isomorfeus.raise_error(message: "Unknown key word(s) at the beginning of the line: #{line}") unless operation[:procedure].empty?
55
- operation[:description] = [] unless operation.key?(:description)
56
- operation[:description] << line.strip
57
- end
58
- end
59
-
60
- operation
61
- end
62
- end
63
- end
1
+ module LucidOperation
2
+ module Gherkin
3
+ FIRST_EXCEPTION = "First must be the first one that is used and can only used once!"
4
+ FINALLY_EXCEPTION = "Finally, except for Ensure and Failed, must be the last one to be used and can only be used once!"
5
+
6
+ NEWLINE = /\r?\n/
7
+ OPERATION = /^\s*Operation: (.*)$/
8
+ PROCEDURE = /^\s*Procedure: (.*)$/
9
+ STAR = /^\s*\* (.*)$/
10
+ GIVEN = /^\s*Given (.*)$/
11
+ WHEN = /^\s*When (.*)$/
12
+ THEN = /^\s*Then (.*)$/
13
+ AND = /^\s*And (.*)$/
14
+ FIRST = /^\s*First (.*)$/
15
+ ENSURE = /^\s*Ensure (.*)$/
16
+ FINALLY = /^\s*Finally (.*)$/
17
+ IW_FAILING = /^\s*(?:When|If) failing (.*)$/
18
+ IF_ITT_FAILED = /^\s*If (?:that|this|it) failed (.*)$/
19
+ FAILED = /^\s*Failed (.*)$/
20
+ COMMENT = /^\s*# (.*)$/
21
+ WHITE_SPACE = /^\s*$/
22
+
23
+ def self.parse(gherkin_text)
24
+ operation = { operation: '', procedure: '', steps: [], failure: [], ensure: [] }
25
+ has_finally = false
26
+ lines = gherkin_text.split(NEWLINE)
27
+
28
+ lines.each do |line|
29
+ case line
30
+ when STAR, GIVEN, WHEN, THEN, AND
31
+ Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
32
+ operation[:steps] << $1.strip
33
+ when ENSURE
34
+ operation[:ensure] << $1.strip
35
+ when IW_FAILING, IF_ITT_FAILED, FAILED
36
+ operation[:failure] << $1.strip
37
+ when FIRST
38
+ Isomorfeus.raise_error(message: FIRST_EXCEPTION) if operation[:steps].size > 0
39
+ operation[:steps] << $1.strip
40
+ when FINALLY
41
+ Isomorfeus.raise_error(message: FINALLY_EXCEPTION) if has_finally
42
+ operation[:steps] << $1.strip
43
+ has_finally = true
44
+ when PROCEDURE
45
+ Isomorfeus.raise_error(message: 'No Operation defined!') if operation[:operation].empty?
46
+ Isomorfeus.raise_error(message: 'Procedure already defined!') unless operation[:procedure].empty?
47
+ operation[:procedure] = $1.strip
48
+ when OPERATION
49
+ Isomorfeus.raise_error(message: 'Operation already defined!') unless operation[:operation].empty?
50
+ operation[:operation] = $1.strip
51
+ when WHITE_SPACE, COMMENT
52
+ # nothing, just skip
53
+ else
54
+ Isomorfeus.raise_error(message: "Unknown key word(s) at the beginning of the line: #{line}") unless operation[:procedure].empty?
55
+ operation[:description] = [] unless operation.key?(:description)
56
+ operation[:description] << line.strip
57
+ end
58
+ end
59
+
60
+ operation
61
+ end
62
+ end
63
+ end