range_dsl 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/range_dsl/connection_exp.rb +10 -0
- data/lib/range_dsl/container_exp.rb +10 -0
- data/lib/range_dsl/exact_exp.rb +9 -0
- data/lib/range_dsl/filter_exp.rb +20 -0
- data/lib/range_dsl/open_range_exp.rb +9 -0
- data/range_dsl.gemspec +1 -1
- data/spec/range_dsl_spec.rb +13 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -27,6 +27,16 @@ module RangeDsl
|
|
27
27
|
"#{left_str} #{name_for_inspect} #{right_str}"
|
28
28
|
end
|
29
29
|
|
30
|
+
def eql?(other)
|
31
|
+
(other.class == self.class) &&
|
32
|
+
self.left.eql?(other.left) && self.right.eql?(other.right)
|
33
|
+
end
|
34
|
+
alias_method :==, :eql?
|
35
|
+
|
36
|
+
def hash
|
37
|
+
"#{self.class.name}:#{inspect}".hash
|
38
|
+
end
|
39
|
+
|
30
40
|
private
|
31
41
|
def require_brace?(other)
|
32
42
|
return false unless other.is_a?(ConnectionExp::Base)
|
@@ -14,6 +14,16 @@ module RangeDsl
|
|
14
14
|
args = @values.inspect.gsub(/^\[|\]$/, '')
|
15
15
|
"#{name_for_inspect}(#{args})"
|
16
16
|
end
|
17
|
+
|
18
|
+
def eql?(other)
|
19
|
+
(other.class == self.class) && (self.values == other.values)
|
20
|
+
end
|
21
|
+
alias_method :==, :eql?
|
22
|
+
|
23
|
+
def hash
|
24
|
+
"#{self.class.name}:#{inspect}".hash
|
25
|
+
end
|
26
|
+
|
17
27
|
end
|
18
28
|
|
19
29
|
class Any < Base
|
data/lib/range_dsl/exact_exp.rb
CHANGED
@@ -17,6 +17,15 @@ module RangeDsl
|
|
17
17
|
def inspect
|
18
18
|
"eq(#{@value.inspect})"
|
19
19
|
end
|
20
|
+
|
21
|
+
def eql?(other)
|
22
|
+
(other.value == self.value) && (other.class == self.class)
|
23
|
+
end
|
24
|
+
alias_method :==, :eql?
|
25
|
+
|
26
|
+
def hash
|
27
|
+
"#{self.class.name}:#{inspect}".hash
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
31
|
class NotEqual < Equal
|
data/lib/range_dsl/filter_exp.rb
CHANGED
@@ -17,11 +17,21 @@ module RangeDsl
|
|
17
17
|
def inspect
|
18
18
|
"not_be(#{@src.inspect})"
|
19
19
|
end
|
20
|
+
|
21
|
+
def eql?(other)
|
22
|
+
(other.class == self.class) && self.src.eql?(other.src)
|
23
|
+
end
|
24
|
+
alias_method :==, :eql?
|
25
|
+
|
26
|
+
def hash
|
27
|
+
"#{self.class.name}:#{inspect}".hash
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
31
|
class Func
|
23
32
|
include ConnectionExp::Client
|
24
33
|
|
34
|
+
attr_reader :block_str
|
25
35
|
def initialize(block_str = nil, &block)
|
26
36
|
@block_str = block_str
|
27
37
|
@block = block
|
@@ -34,6 +44,16 @@ module RangeDsl
|
|
34
44
|
def inspect
|
35
45
|
"func" << (@block_str ? "(#{@block_str.inspect})" : '{}')
|
36
46
|
end
|
47
|
+
|
48
|
+
def eql?(other)
|
49
|
+
return false if @block_str.nil?
|
50
|
+
(other.class == self.class) && self.block_str.eql?(other.block_str)
|
51
|
+
end
|
52
|
+
alias_method :==, :eql?
|
53
|
+
|
54
|
+
def hash
|
55
|
+
"#{self.class.name}:#{inspect}".hash
|
56
|
+
end
|
37
57
|
end
|
38
58
|
|
39
59
|
end
|
@@ -20,6 +20,15 @@ module RangeDsl
|
|
20
20
|
def inspect
|
21
21
|
"#{name_for_inspect}(#{@value.inspect})"
|
22
22
|
end
|
23
|
+
|
24
|
+
def eql?(other)
|
25
|
+
(other.value == self.value) && (other.class == self.class)
|
26
|
+
end
|
27
|
+
alias_method :==, :eql?
|
28
|
+
|
29
|
+
def hash
|
30
|
+
"#{self.class.name}:#{inspect}".hash
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
class GreaterThanEqual < Base
|
data/range_dsl.gemspec
CHANGED
data/spec/range_dsl_spec.rb
CHANGED
@@ -4,9 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
4
4
|
describe "RangeDsl" do
|
5
5
|
describe "introduction" do
|
6
6
|
it "1,2と5以上はtrue" do
|
7
|
-
r = RangeDsl.compile
|
8
|
-
any 1, 2, gte(5)
|
9
|
-
end
|
7
|
+
r = RangeDsl.compile{any 1, 2, gte(5)}
|
10
8
|
r.include?(-10000).should == false
|
11
9
|
r.include?(0).should == false
|
12
10
|
r.include?(1).should == true
|
@@ -16,6 +14,7 @@ describe "RangeDsl" do
|
|
16
14
|
r.include?(5).should == true
|
17
15
|
r.include?(6).should == true
|
18
16
|
r.include?(10000).should == true
|
17
|
+
r.should == RangeDsl.compile{any 1, 2, gte(5)}
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -29,6 +28,7 @@ describe "RangeDsl" do
|
|
29
28
|
@r1.include?(100.0).should == true
|
30
29
|
@r1.include?(1234567890).should == true
|
31
30
|
@r1.inspect.should == "gte(100)"
|
31
|
+
@r1.should == RangeDsl.gte(100)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -91,11 +91,12 @@ describe "RangeDsl" do
|
|
91
91
|
@r1.include?(100.0001).should == false
|
92
92
|
@r1.include?(101).should == false
|
93
93
|
@r1.inspect.should == "eq(100)"
|
94
|
+
@r1.should == RangeDsl.eq(100)
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
98
|
-
describe "
|
99
|
+
describe "neq" do
|
99
100
|
[:neq, :not_equal].each do |operator|
|
100
101
|
it operator do
|
101
102
|
@r1 = RangeDsl.send(operator, 100)
|
@@ -106,6 +107,7 @@ describe "RangeDsl" do
|
|
106
107
|
@r1.include?(100.0001).should == true
|
107
108
|
@r1.include?(101).should == true
|
108
109
|
@r1.inspect.should == "neq(100)"
|
110
|
+
@r1.should == RangeDsl.neq(100)
|
109
111
|
end
|
110
112
|
end
|
111
113
|
end
|
@@ -130,6 +132,7 @@ describe "RangeDsl" do
|
|
130
132
|
@r1.include?(7.1).should == false
|
131
133
|
@r1.include?(8).should == false
|
132
134
|
@r1.inspect.should == "any(3, 7)"
|
135
|
+
@r1.should == RangeDsl.any(3, 7)
|
133
136
|
end
|
134
137
|
end
|
135
138
|
end
|
@@ -148,6 +151,7 @@ describe "RangeDsl" do
|
|
148
151
|
r1.include?(100.1).should == true
|
149
152
|
r1.include?(101).should == true
|
150
153
|
r1.inspect.should == "not_be(eq(100))"
|
154
|
+
r1.should == RangeDsl.compile{ not_be(eq(100)) }
|
151
155
|
end
|
152
156
|
end
|
153
157
|
|
@@ -170,6 +174,7 @@ describe "RangeDsl" do
|
|
170
174
|
@r2.include?(6.1).should == false
|
171
175
|
@r2.include?(7).should == false
|
172
176
|
@r2.inspect.should == "gt(3) & lt(6)"
|
177
|
+
@r2.should == RangeDsl.compile{ gt(3) & lt(6) }
|
173
178
|
end
|
174
179
|
end
|
175
180
|
end
|
@@ -267,6 +272,8 @@ describe "RangeDsl" do
|
|
267
272
|
r1.include?(2).should == false
|
268
273
|
r1.include?(3).should == true
|
269
274
|
r1.inspect.should == "gte(1) & func{}"
|
275
|
+
# func{|v| v % 2 == 1} のブロックが取得できないので、常に一致しません。
|
276
|
+
r1.should_not == RangeDsl.compile{ gt(3) & lt(6) }
|
270
277
|
end
|
271
278
|
|
272
279
|
it "動的なブロックはinspectで出力できないので、文字列でも渡せるように" do
|
@@ -278,6 +285,7 @@ describe "RangeDsl" do
|
|
278
285
|
r1.include?(2).should == false
|
279
286
|
r1.include?(3).should == true
|
280
287
|
r1.inspect.should == "gte(1) & func(\"{|v| v % 2 == 1}\")"
|
288
|
+
r1.should == RangeDsl.compile("gte(1) & func(\"{|v| v % 2 == 1}\")")
|
281
289
|
end
|
282
290
|
end
|
283
291
|
end
|
@@ -286,6 +294,7 @@ describe "RangeDsl" do
|
|
286
294
|
it "lt(3) | gt(30) | any(2, 14, 36)" do
|
287
295
|
r2 = RangeDsl.compile("lt(3) | gt(30) | any(12, 14, 16)")
|
288
296
|
r2.inspect.should == "lt(3) | gt(30) | any(12, 14, 16)"
|
297
|
+
r2.should == RangeDsl.compile("lt(3) | gt(30) | any(12, 14, 16)")
|
289
298
|
end
|
290
299
|
|
291
300
|
it "gte(3) & lt(10) & any(2, 4, 6)" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- akimatter
|