rules_processor 0.1.0
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 +7 -0
- data/.codeclimate.yml +25 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1156 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rules_processor.rb +33 -0
- data/lib/rules_processor/condition_matcher.rb +24 -0
- data/lib/rules_processor/configuration.rb +11 -0
- data/lib/rules_processor/operations/base.rb +40 -0
- data/lib/rules_processor/operations/greater_than.rb +11 -0
- data/lib/rules_processor/operations/greater_than_equal.rb +11 -0
- data/lib/rules_processor/operations/include.rb +14 -0
- data/lib/rules_processor/operations/is.rb +11 -0
- data/lib/rules_processor/operations/is_not.rb +11 -0
- data/lib/rules_processor/operations/less_than.rb +11 -0
- data/lib/rules_processor/operations/less_than_equal.rb +11 -0
- data/lib/rules_processor/operations/normalize_array.rb +15 -0
- data/lib/rules_processor/operations/not_include.rb +14 -0
- data/lib/rules_processor/operators_to_select.rb +21 -0
- data/lib/rules_processor/processor.rb +62 -0
- data/lib/rules_processor/rule_matcher.rb +38 -0
- data/lib/rules_processor/version.rb +3 -0
- data/rules_processor.gemspec +27 -0
- metadata +115 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
module RulesProcessor
|
2
|
+
class RuleMatcher
|
3
|
+
|
4
|
+
attr_accessor :records, :rule, :options
|
5
|
+
|
6
|
+
def initialize(args = {})
|
7
|
+
@records = args[:records]
|
8
|
+
@rule = args[:rule]
|
9
|
+
@options = args[:options]
|
10
|
+
end
|
11
|
+
|
12
|
+
def matches?
|
13
|
+
return false if both_condition_group_empty?
|
14
|
+
meet_all_matches? || meet_any_matches?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def both_condition_group_empty?
|
20
|
+
rule.meet_all.empty? && rule.meet_any.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def meet_all_matches?
|
24
|
+
return false if rule.meet_all.empty?
|
25
|
+
rule.meet_all.all? { |c| condition_matcher(c).matches? }
|
26
|
+
end
|
27
|
+
|
28
|
+
def meet_any_matches?
|
29
|
+
return false if rule.meet_any.empty?
|
30
|
+
rule.meet_any.any? { |c| condition_matcher(c).matches? }
|
31
|
+
end
|
32
|
+
|
33
|
+
def condition_matcher(condition)
|
34
|
+
RulesProcessor::ConditionMatcher.new(records: records, options: options, condition: condition)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rules_processor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rules_processor'
|
8
|
+
spec.version = RulesProcessor::VERSION
|
9
|
+
spec.authors = ['Rafal Grabowski']
|
10
|
+
spec.email = ['rafal.grabowski@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Business Rules Processor.}
|
13
|
+
spec.description = %q{A simple business rules processor.}
|
14
|
+
spec.homepage = 'https://github.com/rgrabowski/rules_processor'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rules_processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafal Grabowski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A simple business rules processor.
|
56
|
+
email:
|
57
|
+
- rafal.grabowski@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".codeclimate.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/rules_processor.rb
|
74
|
+
- lib/rules_processor/condition_matcher.rb
|
75
|
+
- lib/rules_processor/configuration.rb
|
76
|
+
- lib/rules_processor/operations/base.rb
|
77
|
+
- lib/rules_processor/operations/greater_than.rb
|
78
|
+
- lib/rules_processor/operations/greater_than_equal.rb
|
79
|
+
- lib/rules_processor/operations/include.rb
|
80
|
+
- lib/rules_processor/operations/is.rb
|
81
|
+
- lib/rules_processor/operations/is_not.rb
|
82
|
+
- lib/rules_processor/operations/less_than.rb
|
83
|
+
- lib/rules_processor/operations/less_than_equal.rb
|
84
|
+
- lib/rules_processor/operations/normalize_array.rb
|
85
|
+
- lib/rules_processor/operations/not_include.rb
|
86
|
+
- lib/rules_processor/operators_to_select.rb
|
87
|
+
- lib/rules_processor/processor.rb
|
88
|
+
- lib/rules_processor/rule_matcher.rb
|
89
|
+
- lib/rules_processor/version.rb
|
90
|
+
- rules_processor.gemspec
|
91
|
+
homepage: https://github.com/rgrabowski/rules_processor
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Business Rules Processor.
|
115
|
+
test_files: []
|