isomorfeus-operation 1.0.0.zeta23 → 2.0.0.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +16 -16
- data/lib/isomorfeus/operation/config.rb +29 -29
- data/lib/isomorfeus/operation/handler/operation_handler.rb +65 -65
- data/lib/isomorfeus/operation/version.rb +5 -5
- data/lib/isomorfeus-operation.rb +29 -27
- data/lib/isomorfeus_operation/lucid_local_operation/base.rb +9 -10
- data/lib/isomorfeus_operation/lucid_local_operation/mixin.rb +35 -35
- data/lib/isomorfeus_operation/lucid_operation/base.rb +10 -11
- data/lib/isomorfeus_operation/lucid_operation/gherkin.rb +63 -63
- data/lib/isomorfeus_operation/lucid_operation/mixin.rb +95 -96
- data/lib/isomorfeus_operation/lucid_operation/promise_run.rb +67 -67
- data/lib/isomorfeus_operation/lucid_operation/steps.rb +58 -58
- data/lib/isomorfeus_operation/lucid_quick_op/base.rb +10 -11
- data/lib/isomorfeus_operation/lucid_quick_op/mixin.rb +80 -81
- metadata +38 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f4cf96539068b5adba8c1b88c97f1bea51bffce8c50962ca0cf98116cafcb81
|
4
|
+
data.tar.gz: 7eb4aed8df13169f215bce57deb3085a96099b364195e31e4a350611d556eb94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32d9b9ea728d338e15c382be4db6c46b0dc4d537828ca8a05167755689f6ebca00d2e558949695ad23b2fb8a70b206e9b05f6de7a2beecf35e7fa988b34f2b02
|
7
|
+
data.tar.gz: 792687768914e5f8b2d89932addefb26a7c00653b5eb9ce8366fc9e65d7f454861d03a07781456cbae7e2471508aba808dfb4dada6bf59c0282dd13c4b8e77db
|
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-
|
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 = '
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Operation
|
3
|
+
VERSION = '2.0.0.rc2'
|
4
|
+
end
|
5
|
+
end
|
data/lib/isomorfeus-operation.rb
CHANGED
@@ -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', :
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|