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.
@@ -1,95 +1,95 @@
1
- # frozen_string_literal: true
2
-
3
- module LucidOperation
4
- module Mixin
5
- def self.included(base)
6
- base.extend(LucidPropDeclaration::Mixin)
7
-
8
- if RUBY_ENGINE == 'opal'
9
- base.instance_exec do
10
- def procedure(gherkin_text)
11
- end
12
-
13
- def steps
14
- end
15
- alias :gherkin :steps
16
- alias :ensure_steps :steps
17
- alias :failure_steps :steps
18
- alias :Given :steps
19
- alias :And :steps
20
- alias :Then :steps
21
- alias :When :steps
22
- alias :Ensure :steps
23
- alias :Failed :steps
24
- alias :If_failing :steps
25
- alias :When_failing :steps
26
- alias :If_this_failed :steps
27
- alias :If_that_failed :steps
28
-
29
- def First(regular_expression, &block)
30
- Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
31
- @first_defined = true
32
- end
33
-
34
- def Finally(regular_expression, &block)
35
- Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
36
- @finally_defined = true
37
- end
38
-
39
- def promise_run(**props_hash)
40
- props = validated_props(props_hash)
41
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props).then do |agent|
42
- unless agent.processed
43
- agent.processed = true
44
- if agent.response.key?(:error)
45
- Isomorfeus.raise_error(message: agent.response[:error])
46
- end
47
- agent.result = agent.response[:result]
48
- end
49
- if agent.result.key?(:rejected)
50
- if agent.result.key?(:error)
51
- e = agent.result[:error]
52
- exception_class_name = e[:class_name]
53
- exception_class = exception_class_name.constantize
54
- exception = exception_class.new(e[:message])
55
- exception.set_backtrace(e[:backtrace])
56
- raise exception
57
- else
58
- raise agent.result[:rejected]
59
- end
60
- else
61
- agent.result[:resolved]
62
- end
63
- end
64
- end
65
- end
66
- else
67
- Isomorfeus.add_valid_operation_class(base) unless base == LucidOperation::Base
68
- base.extend(LucidOperation::Steps)
69
- base.include(LucidOperation::PromiseRun)
70
-
71
- base.instance_exec do
72
- def promise_run(**props_hash)
73
- self.new(**props_hash).promise_run
74
- end
75
- end
76
-
77
- attr_reader :props
78
- attr_accessor :step_result
79
-
80
- def initialize(**props_hash)
81
- props_hash = self.class.validated_props(props_hash)
82
- @props = LucidProps.new(props_hash)
83
- end
84
-
85
- def current_user
86
- Isomorfeus.current_user
87
- end
88
-
89
- def pub_sub_client
90
- Isomorfeus.pub_sub_client
91
- end
92
- end
93
- end
94
- end
95
- end
1
+ # frozen_string_literal: true
2
+
3
+ module LucidOperation
4
+ module Mixin
5
+ def self.included(base)
6
+ base.extend(LucidPropDeclaration::Mixin)
7
+
8
+ if RUBY_ENGINE == 'opal'
9
+ base.instance_exec do
10
+ def procedure(gherkin_text)
11
+ end
12
+
13
+ def steps
14
+ end
15
+ alias :gherkin :steps
16
+ alias :ensure_steps :steps
17
+ alias :failure_steps :steps
18
+ alias :Given :steps
19
+ alias :And :steps
20
+ alias :Then :steps
21
+ alias :When :steps
22
+ alias :Ensure :steps
23
+ alias :Failed :steps
24
+ alias :If_failing :steps
25
+ alias :When_failing :steps
26
+ alias :If_this_failed :steps
27
+ alias :If_that_failed :steps
28
+
29
+ def First(regular_expression, &block)
30
+ Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
31
+ @first_defined = true
32
+ end
33
+
34
+ def Finally(regular_expression, &block)
35
+ Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
36
+ @finally_defined = true
37
+ end
38
+
39
+ def promise_run(**props_hash)
40
+ props = validated_props(props_hash)
41
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props).then do |agent|
42
+ unless agent.processed
43
+ agent.processed = true
44
+ if agent.response.key?(:error)
45
+ Isomorfeus.raise_error(message: agent.response[:error])
46
+ end
47
+ agent.result = agent.response[:result]
48
+ end
49
+ if agent.result.key?(:rejected)
50
+ if agent.result.key?(:error)
51
+ e = agent.result[:error]
52
+ exception_class_name = e[:class_name]
53
+ exception_class = exception_class_name.constantize
54
+ exception = exception_class.new(e[:message])
55
+ exception.set_backtrace(e[:backtrace])
56
+ raise exception
57
+ else
58
+ raise agent.result[:rejected]
59
+ end
60
+ else
61
+ agent.result[:resolved]
62
+ end
63
+ end
64
+ end
65
+ end
66
+ else
67
+ Isomorfeus.add_valid_operation_class(base) unless base == LucidOperation::Base
68
+ base.extend(LucidOperation::Steps)
69
+ base.include(LucidOperation::PromiseRun)
70
+
71
+ base.instance_exec do
72
+ def promise_run(**props_hash)
73
+ self.new(**props_hash).promise_run
74
+ end
75
+ end
76
+
77
+ attr_reader :props
78
+ attr_accessor :step_result
79
+
80
+ def initialize(**props_hash)
81
+ props_hash = self.class.validated_props(props_hash)
82
+ @props = LucidProps.new(props_hash)
83
+ end
84
+
85
+ def current_user
86
+ Isomorfeus.current_user
87
+ end
88
+
89
+ def pub_sub_client
90
+ Isomorfeus.pub_sub_client
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,67 +1,67 @@
1
- module LucidOperation
2
- module PromiseRun
3
- def promise_run
4
- promise = Promise.new
5
- original_promise = promise
6
- operation = self
7
-
8
- # steps
9
- self.class.gherkin[:steps].each do |gherkin_step|
10
- matched = false
11
- self.class.steps.each do |step|
12
- # step[0] -> regular_expression
13
- # step[1] -> block
14
- match_data = gherkin_step.match(step[0])
15
- if match_data
16
- matched = true
17
- promise = promise.then do |result|
18
- operation.step_result = result
19
- operation.instance_exec(*match_data, &step[1])
20
- end
21
- end
22
- end
23
- Isomorfeus.raise_error(message: "No match found for step #{gherkin_step}!") unless matched
24
- end
25
-
26
- # fail track
27
- self.class.gherkin[:failure].each do |gherkin_step|
28
- matched = false
29
- self.class.failure_steps.each do |step|
30
- # step[0] -> regular_expression
31
- # step[1] -> block
32
- match_data = gherkin_step.match(step[0])
33
- if match_data
34
- matched = true
35
- promise = promise.fail do |result|
36
- operation.step_result = result
37
- operation.instance_exec(*match_data, &step[1])
38
- end
39
- end
40
- end
41
- Isomorfeus.raise_error(message: "No match found for failure step #{gherkin_step}!") unless matched
42
- end
43
-
44
- # ensure
45
- self.class.gherkin[:ensure].each do |gherkin_step|
46
- matched = false
47
- self.class.ensure_steps.each do |step|
48
- # step[0] -> regular_expression
49
- # step[1] -> block
50
- match_data = gherkin_step.match(step[0])
51
- if match_data
52
- matched = true
53
-
54
- promise = promise.ensure do |result|
55
- operation.step_result = result
56
- operation.instance_exec(*match_data, &step[1])
57
- end
58
- end
59
- end
60
- Isomorfeus.raise_error(message: "No match found for ensure step #{gherkin_step}!") unless matched
61
- end
62
-
63
- original_promise.resolve
64
- promise
65
- end
66
- end
67
- end
1
+ module LucidOperation
2
+ module PromiseRun
3
+ def promise_run
4
+ promise = Promise.new
5
+ original_promise = promise
6
+ operation = self
7
+
8
+ # steps
9
+ self.class.gherkin[:steps].each do |gherkin_step|
10
+ matched = false
11
+ self.class.steps.each do |step|
12
+ # step[0] -> regular_expression
13
+ # step[1] -> block
14
+ match_data = gherkin_step.match(step[0])
15
+ if match_data
16
+ matched = true
17
+ promise = promise.then do |result|
18
+ operation.step_result = result
19
+ operation.instance_exec(*match_data, &step[1])
20
+ end
21
+ end
22
+ end
23
+ Isomorfeus.raise_error(message: "No match found for step #{gherkin_step}!") unless matched
24
+ end
25
+
26
+ # fail track
27
+ self.class.gherkin[:failure].each do |gherkin_step|
28
+ matched = false
29
+ self.class.failure_steps.each do |step|
30
+ # step[0] -> regular_expression
31
+ # step[1] -> block
32
+ match_data = gherkin_step.match(step[0])
33
+ if match_data
34
+ matched = true
35
+ promise = promise.fail do |result|
36
+ operation.step_result = result
37
+ operation.instance_exec(*match_data, &step[1])
38
+ end
39
+ end
40
+ end
41
+ Isomorfeus.raise_error(message: "No match found for failure step #{gherkin_step}!") unless matched
42
+ end
43
+
44
+ # ensure
45
+ self.class.gherkin[:ensure].each do |gherkin_step|
46
+ matched = false
47
+ self.class.ensure_steps.each do |step|
48
+ # step[0] -> regular_expression
49
+ # step[1] -> block
50
+ match_data = gherkin_step.match(step[0])
51
+ if match_data
52
+ matched = true
53
+
54
+ promise = promise.ensure do |result|
55
+ operation.step_result = result
56
+ operation.instance_exec(*match_data, &step[1])
57
+ end
58
+ end
59
+ end
60
+ Isomorfeus.raise_error(message: "No match found for ensure step #{gherkin_step}!") unless matched
61
+ end
62
+
63
+ original_promise.resolve
64
+ promise
65
+ end
66
+ end
67
+ end
@@ -1,58 +1,58 @@
1
- # frozen_string_literal: true
2
-
3
- module LucidOperation
4
- module Steps
5
- def procedure(gherkin_text)
6
- feature_line = gherkin_text.include?('Operation: ') ? '' : "Operation: #{self.name}\n"
7
- scenario_line = feature_line == '' || gherkin_text.include?('Procedure: ') ? '' : " Procedure: #{self.name} executing\n"
8
- @procedure = feature_line + scenario_line + gherkin_text
9
- end
10
-
11
- def gherkin
12
- @gherkin ||= LucidOperation::Gherkin.parse(@procedure)
13
- end
14
-
15
- def ensure_steps
16
- @ensure_steps ||= []
17
- end
18
-
19
- def failure_steps
20
- @failure_steps ||= []
21
- end
22
-
23
- def steps
24
- @steps ||= []
25
- end
26
-
27
- def First(regular_expression, &block)
28
- Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
29
- @first_defined = true
30
- steps << [regular_expression, block]
31
- end
32
-
33
- def Given(regular_expression, &block)
34
- steps << [regular_expression, block]
35
- end
36
- alias :And :Given
37
- alias :Then :Given
38
- alias :When :Given
39
-
40
- def Finally(regular_expression, &block)
41
- Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
42
- @finally_defined = true
43
- steps << [regular_expression, block]
44
- end
45
-
46
- def Ensure(regular_expression, &block)
47
- ensure_steps << [regular_expression, block]
48
- end
49
-
50
- def Failed(regular_expression, &block)
51
- failure_steps << [regular_expression, block]
52
- end
53
- alias :If_failing :Failed
54
- alias :When_failing :Failed
55
- alias :If_this_failed :Failed
56
- alias :If_that_failed :Failed
57
- end
58
- end
1
+ # frozen_string_literal: true
2
+
3
+ module LucidOperation
4
+ module Steps
5
+ def procedure(gherkin_text)
6
+ feature_line = gherkin_text.include?('Operation: ') ? '' : "Operation: #{self.name}\n"
7
+ scenario_line = feature_line == '' || gherkin_text.include?('Procedure: ') ? '' : " Procedure: #{self.name} executing\n"
8
+ @procedure = feature_line + scenario_line + gherkin_text
9
+ end
10
+
11
+ def gherkin
12
+ @gherkin ||= LucidOperation::Gherkin.parse(@procedure)
13
+ end
14
+
15
+ def ensure_steps
16
+ @ensure_steps ||= []
17
+ end
18
+
19
+ def failure_steps
20
+ @failure_steps ||= []
21
+ end
22
+
23
+ def steps
24
+ @steps ||= []
25
+ end
26
+
27
+ def First(regular_expression, &block)
28
+ Isomorfeus.raise_error(message: "#{self}: First already defined, can only be defined once!") if @first_defined
29
+ @first_defined = true
30
+ steps << [regular_expression, block]
31
+ end
32
+
33
+ def Given(regular_expression, &block)
34
+ steps << [regular_expression, block]
35
+ end
36
+ alias :And :Given
37
+ alias :Then :Given
38
+ alias :When :Given
39
+
40
+ def Finally(regular_expression, &block)
41
+ Isomorfeus.raise_error(message: "#{self}: Finally already defined, can only be defined once!") if @finally_defined
42
+ @finally_defined = true
43
+ steps << [regular_expression, block]
44
+ end
45
+
46
+ def Ensure(regular_expression, &block)
47
+ ensure_steps << [regular_expression, block]
48
+ end
49
+
50
+ def Failed(regular_expression, &block)
51
+ failure_steps << [regular_expression, block]
52
+ end
53
+ alias :If_failing :Failed
54
+ alias :When_failing :Failed
55
+ alias :If_this_failed :Failed
56
+ alias :If_that_failed :Failed
57
+ end
58
+ end
@@ -1,11 +1,10 @@
1
- module LucidQuickOp
2
- class Base
3
- include LucidQuickOp::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 LucidQuickOp
2
+ class Base
3
+ def self.inherited(base)
4
+ base.include LucidQuickOp::Mixin
5
+ if RUBY_ENGINE != 'opal'
6
+ Isomorfeus.add_valid_operation_class(base)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,80 +1,80 @@
1
- module LucidQuickOp
2
- module Mixin
3
- def self.included(base)
4
- base.extend(LucidPropDeclaration::Mixin)
5
-
6
- if RUBY_ENGINE == 'opal'
7
- base.instance_exec do
8
- def op
9
- end
10
-
11
- def promise_run(**props_hash)
12
- props = validated_props(props_hash)
13
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props).then do |agent|
14
- unless agent.processed
15
- agent.processed = true
16
- if agent.response.key?(:error)
17
- Isomorfeus.raise_error(message: agent.response[:error])
18
- end
19
- agent.result = agent.response[:result]
20
- end
21
- if agent.result.key?(:rejected)
22
- if agent.result.key?(:error)
23
- e = agent.result[:error]
24
- exception_class_name = e[:class_name]
25
- exception_class = exception_class_name.constantize
26
- exception = exception_class.new(e[:message])
27
- exception.set_backtrace(e[:backtrace])
28
- raise exception
29
- else
30
- raise agent.result[:rejected]
31
- end
32
- else
33
- agent.result[:resolved]
34
- end
35
- end
36
- end
37
- end
38
- else
39
- Isomorfeus.add_valid_operation_class(base) unless base == LucidQuickOp::Base
40
-
41
- base.instance_exec do
42
- def op(&block)
43
- @op = block
44
- end
45
-
46
- def promise_run(**props_hash)
47
- self.new(**props_hash).promise_run
48
- end
49
- end
50
- end
51
- end
52
-
53
- attr_reader :props
54
-
55
- def initialize(**props_hash)
56
- props_hash = self.class.validated_props(props_hash)
57
- @props = LucidProps.new(props_hash)
58
- end
59
-
60
- def promise_run
61
- original_promise = Promise.new
62
-
63
- operation = self
64
- promise = original_promise.then do |_|
65
- operation.instance_exec(&operation.class.instance_variable_get(:@op))
66
- end
67
-
68
- original_promise.resolve
69
- promise
70
- end
71
-
72
- def current_user
73
- Isomorfeus.current_user
74
- end
75
-
76
- def pub_sub_client
77
- Isomorfeus.pub_sub_client
78
- end
79
- end
80
- end
1
+ module LucidQuickOp
2
+ module Mixin
3
+ def self.included(base)
4
+ base.extend(LucidPropDeclaration::Mixin)
5
+
6
+ if RUBY_ENGINE == 'opal'
7
+ base.instance_exec do
8
+ def op
9
+ end
10
+
11
+ def promise_run(**props_hash)
12
+ props = validated_props(props_hash)
13
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.name, props).then do |agent|
14
+ unless agent.processed
15
+ agent.processed = true
16
+ if agent.response.key?(:error)
17
+ Isomorfeus.raise_error(message: agent.response[:error])
18
+ end
19
+ agent.result = agent.response[:result]
20
+ end
21
+ if agent.result.key?(:rejected)
22
+ if agent.result.key?(:error)
23
+ e = agent.result[:error]
24
+ exception_class_name = e[:class_name]
25
+ exception_class = exception_class_name.constantize
26
+ exception = exception_class.new(e[:message])
27
+ exception.set_backtrace(e[:backtrace])
28
+ raise exception
29
+ else
30
+ raise agent.result[:rejected]
31
+ end
32
+ else
33
+ agent.result[:resolved]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ else
39
+ Isomorfeus.add_valid_operation_class(base) unless base == LucidQuickOp::Base
40
+
41
+ base.instance_exec do
42
+ def op(&block)
43
+ @op = block
44
+ end
45
+
46
+ def promise_run(**props_hash)
47
+ self.new(**props_hash).promise_run
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ attr_reader :props
54
+
55
+ def initialize(**props_hash)
56
+ props_hash = self.class.validated_props(props_hash)
57
+ @props = LucidProps.new(props_hash)
58
+ end
59
+
60
+ def promise_run
61
+ original_promise = Promise.new
62
+
63
+ operation = self
64
+ promise = original_promise.then do |_|
65
+ operation.instance_exec(&operation.class.instance_variable_get(:@op))
66
+ end
67
+
68
+ original_promise.resolve
69
+ promise
70
+ end
71
+
72
+ def current_user
73
+ Isomorfeus.current_user
74
+ end
75
+
76
+ def pub_sub_client
77
+ Isomorfeus.pub_sub_client
78
+ end
79
+ end
80
+ end