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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3299d0a6a211dc230999c6236d00bb62cf825dbb
4
- data.tar.gz: 3a8f7bc7ee3eeeeca9a753463679e1f2ad537b90
3
+ metadata.gz: ee502e2ab095bf7798107f3b0ba638b04f59e6d6
4
+ data.tar.gz: cc8430875da2d6176910b998a1e00b552dab0913
5
5
  SHA512:
6
- metadata.gz: f503edffbbf3a4dd0ce74afdd8dc9e0f96ff57ee3bb00ccd75a5cda6f8a946ff586b1a86eb76657d04c3e3d48d339a5b983663cbf165326f9d52b5a41ef0462d
7
- data.tar.gz: d873bb4267ef68573de2d71abfb5cf247ecf12b5d8567584b1461461e8f109ff9aa327458c486319c5f24654b66abcbb5ef182a40b269e107a570cc069157ac7
6
+ metadata.gz: d3396ec4aa5f62d1a243c5abb200533ffcc4b8770e95960bcd3ccfb48484f97fc1a04af8a209c36a04d802a3945907ae9e82a0c276973c25d9cae5156cb1f3bb
7
+ data.tar.gz: 8b6c9b4cf0abb2354f02baeaf3e8e57b9cb1fe26d4fed200487701c95cd0cc5209e15c0296cf0df848a1925b4ef91b785bdba95aa38ce9059c6e471870661edc
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  Gemfile.lock
2
+ pkg/
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.0"
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
- def setup
40
- rb_rules.rule(:hello) { |param| param =~ /hello/ }
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 rb_rules
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.0
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: 2014-12-30 00:00:00.000000000 Z
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: