rulezilla 0.1.4 → 0.4.1
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 +5 -5
- data/.github/workflows/ci.yaml +36 -0
- data/.github/workflows/codeql-analysis.yaml +70 -0
- data/.github/workflows/dobby-actions.yml +29 -0
- data/.github/workflows/gem-publish.yaml +46 -0
- data/.github/workflows/version-forget-me-not.yaml +19 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +61 -0
- data/.ruby-version +1 -0
- data/CODEOWNERS +3 -0
- data/Gemfile +2 -4
- data/LICENSE.txt +9 -0
- data/README.md +34 -28
- data/catalog-info.yaml +8 -0
- data/lib/rulezilla/basic_support.rb +3 -3
- data/lib/rulezilla/dsl.rb +27 -14
- data/lib/rulezilla/node.rb +10 -11
- data/lib/rulezilla/tree.rb +23 -14
- data/lib/rulezilla/version.rb +3 -1
- data/lib/rulezilla.rb +2 -31
- data/rulezilla.gemspec +15 -8
- data/spec/features/{rulezilla_dsl_framwork.feature → rulezilla_dsl_framework.feature} +50 -3
- data/spec/features/step_definitions/rulezilla_dsl_framework_steps.rb +36 -54
- data/spec/spec_helper.rb +33 -13
- metadata +74 -17
- data/Gemfile.lock +0 -44
- data/lib/rulezilla/rule_builder/gherkin_to_condition_rule.rb +0 -63
- data/lib/rulezilla/rule_builder/gherkin_to_result_rule.rb +0 -49
- data/lib/rulezilla/rule_builder.rb +0 -101
- data/spec/features/gherkin_dsl_framework.feature +0 -90
- data/spec/features/gherkin_rules/animal_rule.feature +0 -16
- data/spec/features/gherkin_rules/duration_rule.feature +0 -14
- data/spec/features/step_definitions/rule_steps.rb +0 -64
data/lib/rulezilla/tree.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rulezilla
|
2
4
|
class Tree
|
3
5
|
attr_reader :current_node, :root_node
|
@@ -12,7 +14,9 @@ module Rulezilla
|
|
12
14
|
@current_node = is_root? ? @root_node : @current_node.parent
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
# Returns all the result outcomes of all the matching nodes.
|
18
|
+
#
|
19
|
+
def find_all(record, node = @root_node)
|
16
20
|
array = []
|
17
21
|
if node.applies?(record)
|
18
22
|
node.children.each do |child_node|
|
@@ -21,10 +25,10 @@ module Rulezilla
|
|
21
25
|
|
22
26
|
return node.has_result? ? array + [node] : array
|
23
27
|
end
|
24
|
-
|
28
|
+
array
|
25
29
|
end
|
26
30
|
|
27
|
-
def trace(record, node
|
31
|
+
def trace(record, node = @root_node)
|
28
32
|
if node.applies?(record)
|
29
33
|
node.children.each do |child_node|
|
30
34
|
array = trace(record, child_node)
|
@@ -32,22 +36,26 @@ module Rulezilla
|
|
32
36
|
end
|
33
37
|
return node.has_result? ? [node] : []
|
34
38
|
end
|
35
|
-
|
39
|
+
[]
|
36
40
|
end
|
37
41
|
|
38
|
-
def all_results(record, node
|
42
|
+
def all_results(record, node = @root_node, results = [])
|
39
43
|
if node.has_result?
|
40
|
-
|
44
|
+
begin
|
45
|
+
results << node.result(record)
|
46
|
+
rescue StandardError
|
47
|
+
NoMethodError
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
node.children.each do |child_node|
|
44
52
|
all_results(record, child_node, results)
|
45
53
|
end
|
46
54
|
|
47
|
-
|
55
|
+
results
|
48
56
|
end
|
49
57
|
|
50
|
-
def create_and_move_to_child(name=nil)
|
58
|
+
def create_and_move_to_child(name = nil)
|
51
59
|
node = Node.new
|
52
60
|
node.name = name
|
53
61
|
@current_node.add_child(node)
|
@@ -55,20 +63,21 @@ module Rulezilla
|
|
55
63
|
node
|
56
64
|
end
|
57
65
|
|
58
|
-
def clone_and_append_children(children, node
|
66
|
+
def clone_and_append_children(children, node = @current_node)
|
59
67
|
children.each do |child_node|
|
60
68
|
child_node = child_node.dup
|
61
69
|
node.add_child(child_node)
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
71
|
+
next unless child_node.has_children?
|
72
|
+
|
73
|
+
children_nodes = child_node.children
|
74
|
+
child_node.children = []
|
75
|
+
clone_and_append_children(children_nodes, child_node)
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
71
79
|
private
|
80
|
+
|
72
81
|
def is_root?
|
73
82
|
@current_node == @root_node
|
74
83
|
end
|
data/lib/rulezilla/version.rb
CHANGED
data/lib/rulezilla.rb
CHANGED
@@ -1,35 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rulezilla/node'
|
2
4
|
require 'rulezilla/tree'
|
3
5
|
require 'rulezilla/basic_support'
|
4
6
|
require 'rulezilla/dsl'
|
5
|
-
require 'rulezilla/rule_builder'
|
6
|
-
|
7
|
-
module Rulezilla
|
8
|
-
extend self
|
9
|
-
|
10
|
-
attr_accessor :gherkin_rules_path
|
11
|
-
|
12
|
-
def const_missing(name)
|
13
|
-
raise 'Missing Gherkin Rule Path' if gherkin_rules_path.nil?
|
14
|
-
|
15
|
-
matching_file = Dir.glob(File.join(gherkin_rules_path, '**', '*')).detect do |file|
|
16
|
-
File.basename(file, ".*") == underscore(name.to_s)
|
17
|
-
end
|
18
|
-
|
19
|
-
if matching_file.nil?
|
20
|
-
super
|
21
|
-
else
|
22
|
-
Rulezilla::RuleBuilder.from_file(name, matching_file).build
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def underscore(camel_string)
|
28
|
-
camel_string.gsub(/::/, '/').
|
29
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
30
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
31
|
-
tr("-", "_").
|
32
|
-
downcase
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/rulezilla.gemspec
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
2
5
|
require 'rulezilla/version'
|
3
6
|
|
4
7
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ['
|
6
|
-
gem.email = ['
|
7
|
-
gem.description =
|
8
|
-
gem.summary =
|
9
|
-
gem.homepage =
|
8
|
+
gem.authors = ['Simply Business']
|
9
|
+
gem.email = ['tech@simplybusiness.co.uk']
|
10
|
+
gem.description = 'Rules DSL'
|
11
|
+
gem.summary = 'Rules DSL'
|
12
|
+
gem.homepage = 'https://github.com/simplybusiness/rulezilla'
|
10
13
|
|
11
|
-
gem.files = `git ls-files`.split(
|
14
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
12
15
|
gem.name = 'rulezilla'
|
13
16
|
gem.require_paths = ['lib']
|
14
17
|
gem.version = Rulezilla::VERSION
|
15
18
|
gem.license = 'MIT'
|
16
19
|
|
17
|
-
gem.add_runtime_dependency('
|
20
|
+
gem.add_runtime_dependency('rspec')
|
21
|
+
gem.add_development_dependency('pry')
|
22
|
+
gem.add_development_dependency('pry-doc')
|
23
|
+
gem.add_development_dependency('rubocop')
|
24
|
+
gem.add_development_dependency('turnip')
|
18
25
|
end
|
@@ -85,7 +85,7 @@ Scenario: If nothing is matched in a group, it will fall to default value of the
|
|
85
85
|
Then the result is "It is alright"
|
86
86
|
|
87
87
|
|
88
|
-
Scenario: If nothing is matched, and no default is
|
88
|
+
Scenario: If nothing is matched, and no default is defined in the group, it will fall to the next default
|
89
89
|
Given the rule is:
|
90
90
|
"""
|
91
91
|
group :group_1 do
|
@@ -126,7 +126,7 @@ Scenario: If nothing is matched, it will continue to evaluate the next group
|
|
126
126
|
Then the result is "Bad"
|
127
127
|
|
128
128
|
|
129
|
-
Scenario Outline: It
|
129
|
+
Scenario Outline: It evaluates the rule against a record
|
130
130
|
Given the rule is:
|
131
131
|
"""
|
132
132
|
define :fruit do
|
@@ -185,6 +185,53 @@ Scenario: To get all matching outcomes from a rule
|
|
185
185
|
"""
|
186
186
|
Then all the matching outcomes are "B, C, D, F"
|
187
187
|
|
188
|
+
Scenario: To get all matching outcomes from a rule with root node default result
|
189
|
+
Given the rule is:
|
190
|
+
"""
|
191
|
+
group :may_not_injure_human do
|
192
|
+
condition { not_injure_human? }
|
193
|
+
|
194
|
+
group :obey_human do
|
195
|
+
condition { do_as_human_told? }
|
196
|
+
result(true)
|
197
|
+
|
198
|
+
define :protect_its_own_existence do
|
199
|
+
condition { in_danger? && not_letting_itself_be_detroyed? }
|
200
|
+
result(true)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
default(false)
|
206
|
+
"""
|
207
|
+
When the record has attribute "not_injure_human?" and returns "true"
|
208
|
+
When the record has attribute "do_as_human_told?" and returns "true"
|
209
|
+
When the record has attribute "in_dangert?" and returns "true"
|
210
|
+
When the record has attribute "not_letting_itself_be_detroyed?" and returns "true"
|
211
|
+
Then all the matching outcomes are "true, false"
|
212
|
+
|
213
|
+
Scenario: To get all matching outcomes from a rule without root node default result
|
214
|
+
Given the rule is:
|
215
|
+
"""
|
216
|
+
group :may_not_injure_human do
|
217
|
+
condition { not_injure_human? }
|
218
|
+
|
219
|
+
group :obey_human do
|
220
|
+
condition { do_as_human_told? }
|
221
|
+
result(true)
|
222
|
+
|
223
|
+
define :protect_its_own_existence do
|
224
|
+
condition { in_danger? && not_letting_itself_be_detroyed? }
|
225
|
+
result(true)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
"""
|
230
|
+
When the record has attribute "not_injure_human?" and returns "true"
|
231
|
+
When the record has attribute "do_as_human_told?" and returns "true"
|
232
|
+
When the record has attribute "in_dangert?" and returns "true"
|
233
|
+
When the record has attribute "not_letting_itself_be_detroyed?" and returns "true"
|
234
|
+
Then all the matching outcomes are "true"
|
188
235
|
|
189
236
|
Scenario: Support Module
|
190
237
|
Given the rule class name is "FruitRule"
|
@@ -227,7 +274,7 @@ Scenario Outline: Validate the presence of attributes
|
|
227
274
|
| apple, orange | does not | |
|
228
275
|
|
229
276
|
|
230
|
-
Scenario: Rule return nil if no rule is defined
|
277
|
+
Scenario: Rule return nil if no rule is defined
|
231
278
|
Given the rule is:
|
232
279
|
"""
|
233
280
|
"""
|
@@ -1,40 +1,25 @@
|
|
1
|
-
|
2
|
-
@rule_klass_name = 'DummyRule'
|
3
|
-
@rule_klass = Rulezilla::RuleBuilder.new(@rule_klass_name, gherkin).build
|
4
|
-
end
|
5
|
-
|
6
|
-
step 'the incorrect gherkin is:' do |gherkin|
|
7
|
-
@gherkin = gherkin
|
8
|
-
end
|
9
|
-
|
10
|
-
step 'it raises exception :exception' do |exception|
|
11
|
-
@record ||= {}
|
12
|
-
|
13
|
-
result = result == 'nil' ? nil : result
|
14
|
-
|
15
|
-
expect{ @rule_klass.apply(@record) }.to raise_error{ RuntimeError.new(exception) }
|
16
|
-
end
|
1
|
+
# frozen_string_literal: true
|
17
2
|
|
18
3
|
step 'the rule class name is :klass_name' do |klass_name|
|
19
4
|
@rule_klass_name = klass_name
|
20
5
|
end
|
21
6
|
|
22
7
|
step 'the rule is:' do |rules|
|
23
|
-
@rule_klass = Object.const_set(@rule_klass_name ||
|
24
|
-
@rule_klass.class_eval('include Rulezilla::DSL')
|
8
|
+
@rule_klass = Object.const_set(@rule_klass_name || 'DummyRule', Class.new)
|
9
|
+
@rule_klass.class_eval('include Rulezilla::DSL', __FILE__, __LINE__)
|
25
10
|
@rule_klass.class_eval(rules.to_s)
|
26
11
|
end
|
27
12
|
|
28
13
|
step 'our rule is:' do |rules|
|
29
|
-
@rule_klass = Object.const_set(
|
30
|
-
@rule_klass.class_eval('include Rulezilla::DSL')
|
14
|
+
@rule_klass = Object.const_set('DummyRule', Class.new)
|
15
|
+
@rule_klass.class_eval('include Rulezilla::DSL', __FILE__, __LINE__)
|
31
16
|
@rule_klass.class_eval(rules.to_s)
|
32
17
|
end
|
33
18
|
|
34
19
|
step 'there is a rule called :rule_name:' do |rule_name, rules|
|
35
20
|
send 'the rule class name is :klass_name', rule_name
|
36
|
-
@rule_klass = Object.const_set(@rule_klass_name ||
|
37
|
-
@rule_klass.class_eval('include Rulezilla::DSL')
|
21
|
+
@rule_klass = Object.const_set(@rule_klass_name || 'DummyRule', Class.new)
|
22
|
+
@rule_klass.class_eval('include Rulezilla::DSL', __FILE__, __LINE__)
|
38
23
|
@rule_klass.class_eval(rules.to_s)
|
39
24
|
end
|
40
25
|
|
@@ -47,15 +32,15 @@ end
|
|
47
32
|
step 'the record has attribute :method and returns :value' do |method, value|
|
48
33
|
@record ||= {}
|
49
34
|
value = case value
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
35
|
+
when 'true'
|
36
|
+
true
|
37
|
+
when 'false'
|
38
|
+
false
|
39
|
+
when 'nil'
|
40
|
+
nil
|
41
|
+
else
|
42
|
+
value
|
43
|
+
end
|
59
44
|
@record[method] = value
|
60
45
|
end
|
61
46
|
|
@@ -71,15 +56,15 @@ step 'the result is :result' do |result|
|
|
71
56
|
@record ||= {}
|
72
57
|
|
73
58
|
result = case result
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
59
|
+
when 'true'
|
60
|
+
true
|
61
|
+
when 'false'
|
62
|
+
false
|
63
|
+
when 'nil'
|
64
|
+
nil
|
65
|
+
else
|
66
|
+
result
|
67
|
+
end
|
83
68
|
|
84
69
|
expect(@rule_klass.apply(@record)).to eq result
|
85
70
|
end
|
@@ -90,26 +75,23 @@ step 'all the outcomes are :outcomes' do |outcomes|
|
|
90
75
|
end
|
91
76
|
|
92
77
|
step 'all the matching outcomes are :outcomes' do |outcomes|
|
93
|
-
outcomes = outcomes.split(',').map(&:strip)
|
78
|
+
outcomes = outcomes.split(',').map(&:strip).map do |o|
|
79
|
+
if o == 'true'
|
80
|
+
true
|
81
|
+
else
|
82
|
+
(o == 'false' ? false : o)
|
83
|
+
end
|
84
|
+
end
|
94
85
|
expect(@rule_klass.all(@record)).to match_array outcomes
|
95
86
|
end
|
96
87
|
|
97
|
-
step ':does_or_does_not raise the exception :exception' do |does_or_does_not,
|
88
|
+
step ':does_or_does_not raise the exception :exception' do |does_or_does_not, exception_message|
|
98
89
|
if does_or_does_not == 'does'
|
99
|
-
expect{ @rule_klass.apply @record }.to raise_error do |exception|
|
100
|
-
expect(exception.message).to match
|
90
|
+
expect { @rule_klass.apply @record }.to raise_error do |exception|
|
91
|
+
expect(exception.message).to match(/#{exception_message}/)
|
101
92
|
end
|
102
93
|
else
|
103
|
-
expect{ @rule_klass.apply @record }.not_to raise_error
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
step 'it raises exception :exception' do |exception|
|
108
|
-
expect {
|
109
|
-
@rule_klass_name = 'DummyRule'
|
110
|
-
@rule_klass = Rulezilla::RuleBuilder.new(@rule_klass_name, @gherkin).build
|
111
|
-
}.to raise_error do |exception|
|
112
|
-
expect(exception.message).to match /#{exception}/
|
94
|
+
expect { @rule_klass.apply @record }.not_to raise_error
|
113
95
|
end
|
114
96
|
end
|
115
97
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,21 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rulezilla'
|
2
4
|
require 'pry'
|
3
5
|
|
4
|
-
Dir.glob(
|
5
|
-
|
6
|
-
Rulezilla.gherkin_rules_path = File.join(Dir.pwd, 'spec/features/gherkin_rules')
|
6
|
+
Dir.glob('spec/features/step_definitions/**/*steps.rb') { |f| load f, true }
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.after(:each) do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
begin
|
11
|
+
Object.send(:remove_const, 'DummyRule'.to_sym)
|
12
|
+
rescue StandardError
|
13
|
+
NameError
|
14
|
+
end
|
15
|
+
begin
|
16
|
+
Object.send(:remove_const, 'DummyRuleRecord'.to_sym)
|
17
|
+
rescue StandardError
|
18
|
+
NameError
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
Object.send(:remove_const, 'DummyRuleSupport'.to_sym)
|
22
|
+
rescue StandardError
|
23
|
+
NameError
|
24
|
+
end
|
25
|
+
begin
|
26
|
+
Object.send(:remove_const, @rule_klass_name.to_sym)
|
27
|
+
rescue StandardError
|
28
|
+
NameError
|
29
|
+
end
|
30
|
+
begin
|
31
|
+
Object.send(:remove_const, "#{@rule_klass_name}Record".to_sym)
|
32
|
+
rescue StandardError
|
33
|
+
NameError
|
34
|
+
end
|
35
|
+
begin
|
36
|
+
Object.send(:remove_const, "#{@support_name}Support".to_sym)
|
37
|
+
rescue StandardError
|
38
|
+
NameError
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rulezilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Simply Business
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -24,34 +24,93 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-doc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: turnip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
27
83
|
description: Rules DSL
|
28
84
|
email:
|
29
|
-
-
|
85
|
+
- tech@simplybusiness.co.uk
|
30
86
|
executables: []
|
31
87
|
extensions: []
|
32
88
|
extra_rdoc_files: []
|
33
89
|
files:
|
90
|
+
- ".github/workflows/ci.yaml"
|
91
|
+
- ".github/workflows/codeql-analysis.yaml"
|
92
|
+
- ".github/workflows/dobby-actions.yml"
|
93
|
+
- ".github/workflows/gem-publish.yaml"
|
94
|
+
- ".github/workflows/version-forget-me-not.yaml"
|
34
95
|
- ".gitignore"
|
35
96
|
- ".rspec"
|
97
|
+
- ".rubocop.yml"
|
98
|
+
- ".rubocop_todo.yml"
|
99
|
+
- ".ruby-version"
|
100
|
+
- CODEOWNERS
|
36
101
|
- Gemfile
|
37
|
-
-
|
102
|
+
- LICENSE.txt
|
38
103
|
- README.md
|
104
|
+
- catalog-info.yaml
|
39
105
|
- lib/rulezilla.rb
|
40
106
|
- lib/rulezilla/basic_support.rb
|
41
107
|
- lib/rulezilla/dsl.rb
|
42
108
|
- lib/rulezilla/node.rb
|
43
|
-
- lib/rulezilla/rule_builder.rb
|
44
|
-
- lib/rulezilla/rule_builder/gherkin_to_condition_rule.rb
|
45
|
-
- lib/rulezilla/rule_builder/gherkin_to_result_rule.rb
|
46
109
|
- lib/rulezilla/tree.rb
|
47
110
|
- lib/rulezilla/version.rb
|
48
111
|
- rulezilla.gemspec
|
49
112
|
- spec/features/default_support_methods.feature
|
50
|
-
- spec/features/
|
51
|
-
- spec/features/gherkin_rules/animal_rule.feature
|
52
|
-
- spec/features/gherkin_rules/duration_rule.feature
|
53
|
-
- spec/features/rulezilla_dsl_framwork.feature
|
54
|
-
- spec/features/step_definitions/rule_steps.rb
|
113
|
+
- spec/features/rulezilla_dsl_framework.feature
|
55
114
|
- spec/features/step_definitions/rulezilla_dsl_framework_steps.rb
|
56
115
|
- spec/spec_helper.rb
|
57
116
|
homepage: https://github.com/simplybusiness/rulezilla
|
@@ -73,10 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
132
|
- !ruby/object:Gem::Version
|
74
133
|
version: '0'
|
75
134
|
requirements: []
|
76
|
-
|
77
|
-
rubygems_version: 2.0.14
|
135
|
+
rubygems_version: 3.3.7
|
78
136
|
signing_key:
|
79
137
|
specification_version: 4
|
80
138
|
summary: Rules DSL
|
81
139
|
test_files: []
|
82
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rulezilla (0.1.4)
|
5
|
-
gherkin
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
coderay (1.1.0)
|
11
|
-
diff-lcs (1.2.5)
|
12
|
-
gherkin (2.12.2)
|
13
|
-
multi_json (~> 1.3)
|
14
|
-
method_source (0.8.2)
|
15
|
-
multi_json (1.10.1)
|
16
|
-
pry (0.9.12.6)
|
17
|
-
coderay (~> 1.0)
|
18
|
-
method_source (~> 0.8)
|
19
|
-
slop (~> 3.4)
|
20
|
-
rspec (3.0.0)
|
21
|
-
rspec-core (~> 3.0.0)
|
22
|
-
rspec-expectations (~> 3.0.0)
|
23
|
-
rspec-mocks (~> 3.0.0)
|
24
|
-
rspec-core (3.0.3)
|
25
|
-
rspec-support (~> 3.0.0)
|
26
|
-
rspec-expectations (3.0.3)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.0.0)
|
29
|
-
rspec-mocks (3.0.3)
|
30
|
-
rspec-support (~> 3.0.0)
|
31
|
-
rspec-support (3.0.3)
|
32
|
-
slop (3.5.0)
|
33
|
-
turnip (1.2.2)
|
34
|
-
gherkin (>= 2.5)
|
35
|
-
rspec (>= 2.0, < 4.0)
|
36
|
-
|
37
|
-
PLATFORMS
|
38
|
-
ruby
|
39
|
-
|
40
|
-
DEPENDENCIES
|
41
|
-
pry
|
42
|
-
rspec
|
43
|
-
rulezilla!
|
44
|
-
turnip
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Rulezilla
|
2
|
-
class RuleBuilder
|
3
|
-
class DefaultCondition; end
|
4
|
-
|
5
|
-
class GherkinToConditionRule
|
6
|
-
include Rulezilla::DSL
|
7
|
-
|
8
|
-
define :'this is a "field"' do
|
9
|
-
condition { name =~ /^this is\s?a?n? \"(.*)\"$/i }
|
10
|
-
|
11
|
-
result do
|
12
|
-
field = name.scan(/^this is\s?a?n? \"(.*)\"$/i).flatten.first
|
13
|
-
"#{field}?"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
define :'the "field" is "value"' do
|
18
|
-
condition { name =~ /^the \"(.*)\" is \"(.*)\"$/i }
|
19
|
-
|
20
|
-
result do
|
21
|
-
field, value = name.scan(/^the \"(.*)\" is \"(.*)\"$/i).flatten
|
22
|
-
field = field.gsub(/\s/, '_').downcase
|
23
|
-
|
24
|
-
"#{field} == #{ConditionValueEvaluateRule.apply(value: value)}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
define :'the "field" is in: {table}' do
|
29
|
-
condition { name =~ /^the \"(.*)\" is in:$/i }
|
30
|
-
|
31
|
-
result do
|
32
|
-
field = name.scan(/^the \"(.*)\" is in:$/i).flatten.first
|
33
|
-
field = field.gsub(/\s/, '_').downcase
|
34
|
-
|
35
|
-
values = rows.map{ |row| "#{ConditionValueEvaluateRule.apply(value: row['cells'].first)}" }.join(', ')
|
36
|
-
|
37
|
-
"[#{values}].include?(#{field})"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
define :'none of the above' do
|
42
|
-
condition { name == 'none of the above' }
|
43
|
-
result(DefaultCondition)
|
44
|
-
end
|
45
|
-
|
46
|
-
default { raise "Condition steps is not recognised: #{name}" }
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
class ConditionValueEvaluateRule
|
52
|
-
include Rulezilla::DSL
|
53
|
-
|
54
|
-
define :blank do
|
55
|
-
condition { value == 'blank'}
|
56
|
-
result("''")
|
57
|
-
end
|
58
|
-
|
59
|
-
default { "\"#{value}\"" }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|