rulz 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rulz/evaluator.rb +9 -0
- data/lib/rulz/version.rb +1 -1
- data/spec/rule_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1935cc3549d64ec502daf1321b615888d12e81e3
|
4
|
+
data.tar.gz: 372e6d45ed4c8a646b603db7ba3bb72e8006a8a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1020f6b0ec467ec800254c63b9ef154437c079d32076401b4def27d015822205ab66fa5fbbb2caedc364a406c682b46615b747425a5aed0cabcaaa08d6b94e32
|
7
|
+
data.tar.gz: 592bdade0fdf254ee0a05ccd0a91856a7ae09c255710c9b3f8194d44b891f08d32eaed7a6eabbda53a6e44d29cada814a7336533861c98750f2b74cfeef42964
|
data/lib/rulz/evaluator.rb
CHANGED
@@ -39,6 +39,7 @@ module Rulz
|
|
39
39
|
|
40
40
|
class AttributeCondition < Evaluator::Base
|
41
41
|
def initialize(receiver, attribute, name, *args)
|
42
|
+
@attribute = attribute
|
42
43
|
@condition = Rulz::Attribute::Condition.find(receiver.class, attribute, name)
|
43
44
|
super(receiver, *args)
|
44
45
|
define_singleton_method attribute do
|
@@ -46,6 +47,14 @@ module Rulz
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
50
|
+
def condition(name, *args)
|
51
|
+
Rulz::Evaluator::AttributeCondition.new(@receiver, @attribute, name, *args).evaluate
|
52
|
+
end
|
53
|
+
|
54
|
+
def opposite_of(name, *args)
|
55
|
+
not condition(name, *args)
|
56
|
+
end
|
57
|
+
|
49
58
|
def evaluate
|
50
59
|
instance_exec(*@args, &@condition.proc)
|
51
60
|
end
|
data/lib/rulz/version.rb
CHANGED
data/spec/rule_spec.rb
CHANGED
@@ -179,6 +179,9 @@ describe "rules" do
|
|
179
179
|
condition "greater than" do |other_weight|
|
180
180
|
weight > other_weight
|
181
181
|
end
|
182
|
+
condition "not greater than" do |other_weight|
|
183
|
+
opposite_of "greater than", other_weight
|
184
|
+
end
|
182
185
|
end
|
183
186
|
condition "lopsided" do
|
184
187
|
its.width > its.length
|
@@ -208,6 +211,11 @@ describe "rules" do
|
|
208
211
|
apply! "rotate"
|
209
212
|
end
|
210
213
|
end
|
214
|
+
rule do
|
215
|
+
where weight: ["not greater than", 2] do
|
216
|
+
apply! "cut in half"
|
217
|
+
end
|
218
|
+
end
|
211
219
|
end
|
212
220
|
end
|
213
221
|
end
|
@@ -235,6 +243,12 @@ describe "rules" do
|
|
235
243
|
w.width.should == 4
|
236
244
|
end
|
237
245
|
|
246
|
+
it "should allow attribute conditions to be defined with other attribute conditions" do
|
247
|
+
w = Watermelon.new(4, 2, 4)
|
248
|
+
w.apply_rules!
|
249
|
+
w.length.should == 2
|
250
|
+
end
|
251
|
+
|
238
252
|
end
|
239
253
|
|
240
254
|
context "using predefined conditions" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rulz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chase Conklin
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.0.
|
121
|
+
rubygems_version: 2.0.2
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Enables users to create mail-like rules for processing Ruby objects.
|