rbrules 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +18 -0
- data/lib/rbrules.rb +11 -0
- data/rbrules.gemspec +2 -2
- data/spec/rbrules_spec.rb +20 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee502e2ab095bf7798107f3b0ba638b04f59e6d6
|
4
|
+
data.tar.gz: cc8430875da2d6176910b998a1e00b552dab0913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3396ec4aa5f62d1a243c5abb200533ffcc4b8770e95960bcd3ccfb48484f97fc1a04af8a209c36a04d802a3945907ae9e82a0c276973c25d9cae5156cb1f3bb
|
7
|
+
data.tar.gz: 8b6c9b4cf0abb2354f02baeaf3e8e57b9cb1fe26d4fed200487701c95cd0cc5209e15c0296cf0df848a1925b4ef91b785bdba95aa38ce9059c6e471870661edc
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -65,6 +65,24 @@ matching_rule = RbRules[:random_rules].any?(3)
|
|
65
65
|
matching_rule.magic_number # => 3
|
66
66
|
```
|
67
67
|
|
68
|
+
Adding new rules to an existing one
|
69
|
+
|
70
|
+
You can add new rules to existing ones using the `ruby + ` operator.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
new_rule = RbRules.new do |rules|
|
74
|
+
rules.rule(:alive) { |age| age < 1000 }
|
75
|
+
end
|
76
|
+
|
77
|
+
NEW_HOUSE_RULES = MY_HOUSE_MY_RULES + new_rule
|
78
|
+
|
79
|
+
NEW_HOUSE_RULES.all? 19 # => false
|
80
|
+
NEW_HOUSE_RULES.all? 22 # => false
|
81
|
+
NEW_HOUSE_RULES.any? 95 # => true
|
82
|
+
NEW_HOUSE_RULES.all? 94 # => true
|
83
|
+
```
|
84
|
+
|
85
|
+
|
68
86
|
## Contributing
|
69
87
|
|
70
88
|
1. Fork it
|
data/lib/rbrules.rb
CHANGED
@@ -4,6 +4,17 @@ class RbRules
|
|
4
4
|
|
5
5
|
@rule_sets = Hash.new { |hash, key| hash[key] = new }
|
6
6
|
|
7
|
+
def +(other)
|
8
|
+
self.class.new do |builder|
|
9
|
+
rules.each { |rule| builder.rule(rule) }
|
10
|
+
if other.is_a?(self.class)
|
11
|
+
other.rules.each { |rule| builder.rule(rule) }
|
12
|
+
else
|
13
|
+
builder.rule(other)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
def self.[](key)
|
8
19
|
@rule_sets[key]
|
9
20
|
end
|
data/rbrules.gemspec
CHANGED
@@ -4,8 +4,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rbrules"
|
7
|
-
spec.version = "0.1.
|
8
|
-
spec.authors = ["Gabriel Schammah", "Juan Barreneche"]
|
7
|
+
spec.version = "0.1.1"
|
8
|
+
spec.authors = ["Gabriel Schammah", "Juan Barreneche", "Santiago Carullo"]
|
9
9
|
spec.email = ["devs@restorando.com"]
|
10
10
|
spec.homepage = "http://engineering.restorando.com"
|
11
11
|
spec.description = %q{Declare rule sets to check your objects against them later}
|
data/spec/rbrules_spec.rb
CHANGED
@@ -12,6 +12,10 @@ class TestRbRules < MiniTest::Test
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_number_of_rules
|
16
|
+
assert_equal 2, rb_rules.rules.size
|
17
|
+
end
|
18
|
+
|
15
19
|
def test_any?
|
16
20
|
assert rb_rules.any?('hello')
|
17
21
|
assert rb_rules.any?('world')
|
@@ -32,17 +36,27 @@ class TestRbRules < MiniTest::Test
|
|
32
36
|
refute rb_rules.none?('hello')
|
33
37
|
end
|
34
38
|
|
39
|
+
def test_sum
|
40
|
+
|
41
|
+
rb_rule_extra = RbRules.new do |rules|
|
42
|
+
rules.rule(:extra) { true }
|
43
|
+
end
|
44
|
+
|
45
|
+
combined_rules = rb_rules + rb_rule_extra
|
46
|
+
|
47
|
+
assert_equal 3, combined_rules.rules.size
|
48
|
+
assert rb_rule_extra.rules.all? { |r| combined_rules.rules.include?(r) }
|
49
|
+
end
|
50
|
+
|
35
51
|
end
|
36
52
|
|
37
53
|
class TestSingleton < TestRbRules
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
rb_rules.rule ->(param) { param =~ /world/ }
|
42
|
-
end
|
55
|
+
RbRules[:test].rule(:hello) { |param| param =~ /hello/ }
|
56
|
+
RbRules[:test].rule ->(param) { param =~ /world/ }
|
43
57
|
|
44
|
-
def
|
45
|
-
RbRules[:test]
|
58
|
+
def setup
|
59
|
+
@rb_rules = RbRules[:test]
|
46
60
|
end
|
47
61
|
|
48
62
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbrules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Schammah
|
8
8
|
- Juan Barreneche
|
9
|
+
- Santiago Carullo
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: minitest
|
@@ -97,3 +98,4 @@ summary: This library simplifies a rule set definition that can later be used to
|
|
97
98
|
doesn't satisfy.
|
98
99
|
test_files:
|
99
100
|
- spec/rbrules_spec.rb
|
101
|
+
has_rdoc:
|