dbldots_oedipus 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.md +435 -0
  6. data/Rakefile +26 -0
  7. data/ext/oedipus/extconf.rb +72 -0
  8. data/ext/oedipus/lexing.c +96 -0
  9. data/ext/oedipus/lexing.h +20 -0
  10. data/ext/oedipus/oedipus.c +339 -0
  11. data/ext/oedipus/oedipus.h +58 -0
  12. data/lib/oedipus.rb +40 -0
  13. data/lib/oedipus/comparison.rb +88 -0
  14. data/lib/oedipus/comparison/between.rb +21 -0
  15. data/lib/oedipus/comparison/equal.rb +21 -0
  16. data/lib/oedipus/comparison/gt.rb +21 -0
  17. data/lib/oedipus/comparison/gte.rb +21 -0
  18. data/lib/oedipus/comparison/in.rb +21 -0
  19. data/lib/oedipus/comparison/lt.rb +21 -0
  20. data/lib/oedipus/comparison/lte.rb +21 -0
  21. data/lib/oedipus/comparison/not.rb +25 -0
  22. data/lib/oedipus/comparison/not_equal.rb +21 -0
  23. data/lib/oedipus/comparison/not_in.rb +21 -0
  24. data/lib/oedipus/comparison/outside.rb +21 -0
  25. data/lib/oedipus/comparison/shortcuts.rb +144 -0
  26. data/lib/oedipus/connection.rb +124 -0
  27. data/lib/oedipus/connection/pool.rb +133 -0
  28. data/lib/oedipus/connection/registry.rb +56 -0
  29. data/lib/oedipus/connection_error.rb +14 -0
  30. data/lib/oedipus/index.rb +320 -0
  31. data/lib/oedipus/query_builder.rb +185 -0
  32. data/lib/oedipus/rspec/test_rig.rb +132 -0
  33. data/lib/oedipus/version.rb +12 -0
  34. data/oedipus.gemspec +42 -0
  35. data/spec/data/.gitkeep +0 -0
  36. data/spec/integration/connection/registry_spec.rb +50 -0
  37. data/spec/integration/connection_spec.rb +156 -0
  38. data/spec/integration/index_spec.rb +442 -0
  39. data/spec/spec_helper.rb +16 -0
  40. data/spec/unit/comparison/between_spec.rb +36 -0
  41. data/spec/unit/comparison/equal_spec.rb +22 -0
  42. data/spec/unit/comparison/gt_spec.rb +22 -0
  43. data/spec/unit/comparison/gte_spec.rb +22 -0
  44. data/spec/unit/comparison/in_spec.rb +22 -0
  45. data/spec/unit/comparison/lt_spec.rb +22 -0
  46. data/spec/unit/comparison/lte_spec.rb +22 -0
  47. data/spec/unit/comparison/not_equal_spec.rb +22 -0
  48. data/spec/unit/comparison/not_in_spec.rb +22 -0
  49. data/spec/unit/comparison/not_spec.rb +37 -0
  50. data/spec/unit/comparison/outside_spec.rb +36 -0
  51. data/spec/unit/comparison/shortcuts_spec.rb +125 -0
  52. data/spec/unit/comparison_spec.rb +109 -0
  53. data/spec/unit/query_builder_spec.rb +205 -0
  54. metadata +164 -0
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::Between do
13
+ context "with an inclusive range" do
14
+ let(:comparison) { Oedipus::Comparison::Between.new(42..100) }
15
+
16
+ it "draws as BETWEEN x AND y" do
17
+ comparison.to_sql.should == ["BETWEEN ? AND ?", 42, 100]
18
+ end
19
+
20
+ it "inverses as NOT BETWEEN x AND y" do
21
+ comparison.inverse.to_sql.should == ["NOT BETWEEN ? AND ?", 42, 100]
22
+ end
23
+ end
24
+
25
+ context "with an exclusive range" do
26
+ let(:comparison) { Oedipus::Comparison::Between.new(42...100) }
27
+
28
+ it "draws as BETWEEN x AND y-1" do
29
+ comparison.to_sql.should == ["BETWEEN ? AND ?", 42, 99]
30
+ end
31
+
32
+ it "inverses as NOT BETWEEN x AND y-1" do
33
+ comparison.inverse.to_sql.should == ["NOT BETWEEN ? AND ?", 42, 99]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::Equal do
13
+ let(:comparison) { Oedipus::Comparison::Equal.new('test') }
14
+
15
+ it "draws as = v" do
16
+ comparison.to_sql.should == ["= ?", "test"]
17
+ end
18
+
19
+ it "inverses as != v" do
20
+ comparison.inverse.to_sql.should == ["!= ?", "test"]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::GT do
13
+ let(:comparison) { Oedipus::Comparison::GT.new(42) }
14
+
15
+ it "draws as > v" do
16
+ comparison.to_sql.should == ["> ?", 42]
17
+ end
18
+
19
+ it "inverses as <= v" do
20
+ comparison.inverse.to_sql.should == ["<= ?", 42]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::GTE do
13
+ let(:comparison) { Oedipus::Comparison::GTE.new(42) }
14
+
15
+ it "draws as >= v" do
16
+ comparison.to_sql.should == [">= ?", 42]
17
+ end
18
+
19
+ it "inverses as < v" do
20
+ comparison.inverse.to_sql.should == ["< ?", 42]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::In do
13
+ let(:comparison) { Oedipus::Comparison::In.new([1, 2, 3]) }
14
+
15
+ it "draws as IN (x, y, z)" do
16
+ comparison.to_sql.should == ["IN (?, ?, ?)", 1, 2, 3]
17
+ end
18
+
19
+ it "inverses as NOT IN (x, y, z)" do
20
+ comparison.inverse.to_sql.should == ["NOT IN (?, ?, ?)", 1, 2, 3]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::LT do
13
+ let(:comparison) { Oedipus::Comparison::LT.new(42) }
14
+
15
+ it "draws as < v" do
16
+ comparison.to_sql.should == ["< ?", 42]
17
+ end
18
+
19
+ it "inverses as >= v" do
20
+ comparison.inverse.to_sql.should == [">= ?", 42]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::LTE do
13
+ let(:comparison) { Oedipus::Comparison::LTE.new(42) }
14
+
15
+ it "draws as <= v" do
16
+ comparison.to_sql.should == ["<= ?", 42]
17
+ end
18
+
19
+ it "inverses as > v" do
20
+ comparison.inverse.to_sql.should == ["> ?", 42]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::NotEqual do
13
+ let(:comparison) { Oedipus::Comparison::NotEqual.new('test') }
14
+
15
+ it "draws as != v" do
16
+ comparison.to_sql.should == ["!= ?", "test"]
17
+ end
18
+
19
+ it "inverses as = v" do
20
+ comparison.inverse.to_sql.should == ["= ?", "test"]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::NotIn do
13
+ let(:comparison) { Oedipus::Comparison::NotIn.new([1, 2, 3]) }
14
+
15
+ it "draws as NOT IN (x, y, z)" do
16
+ comparison.to_sql.should == ["NOT IN (?, ?, ?)", 1, 2, 3]
17
+ end
18
+
19
+ it "inverses as IN (x, y, z)" do
20
+ comparison.inverse.to_sql.should == ["IN (?, ?, ?)", 1, 2, 3]
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::In do
13
+ context "with a non-comparison" do
14
+ let(:comparison) { Oedipus::Comparison::Not.new(0..10) }
15
+
16
+ it "converts to a comparison" do
17
+ comparison.v.should be_a_kind_of(Oedipus::Comparison)
18
+ end
19
+
20
+ it "returns the comparison as its inverse" do
21
+ comparison.inverse.should == comparison.v
22
+ end
23
+ end
24
+
25
+ context "with a comparison" do
26
+ let(:original) { Oedipus::Comparison::GTE.new(7) }
27
+ let(:comparison) { Oedipus::Comparison::Not.new(original) }
28
+
29
+ it "draws as the inverse of the comparison" do
30
+ comparison.to_sql.should == original.inverse.to_sql
31
+ end
32
+
33
+ it "inverses as the original" do
34
+ comparison.inverse.to_sql == original.to_sql
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::Outside do
13
+ context "with an inclusive range" do
14
+ let(:comparison) { Oedipus::Comparison::Outside.new(42..100) }
15
+
16
+ it "draws as NOT BETWEEN x AND y" do
17
+ comparison.to_sql.should == ["NOT BETWEEN ? AND ?", 42, 100]
18
+ end
19
+
20
+ it "inverses as BETWEEN x AND y" do
21
+ comparison.inverse.to_sql.should == ["BETWEEN ? AND ?", 42, 100]
22
+ end
23
+ end
24
+
25
+ context "with an exclusive range" do
26
+ let(:comparison) { Oedipus::Comparison::Outside.new(42...100) }
27
+
28
+ it "draws as NOT BETWEEN x AND y-1" do
29
+ comparison.to_sql.should == ["NOT BETWEEN ? AND ?", 42, 99]
30
+ end
31
+
32
+ it "inverses as BETWEEN x AND y-1" do
33
+ comparison.inverse.to_sql.should == ["BETWEEN ? AND ?", 42, 99]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison::Shortcuts do
13
+ let(:s) { Object.new.tap { |o| o.extend subject } }
14
+
15
+ describe "#eq" do
16
+ it "returns the = comparison for v" do
17
+ s.eq(7).should == Oedipus::Comparison::Equal.new(7)
18
+ end
19
+ end
20
+
21
+ describe "#neq" do
22
+ it "returns the != comparison for v" do
23
+ s.neq(7).should == Oedipus::Comparison::NotEqual.new(7)
24
+ end
25
+ end
26
+
27
+
28
+ describe "#not" do
29
+ it "returns the NOT comparison for v" do
30
+ s.not(7).should == Oedipus::Comparison::Not.new(7)
31
+ end
32
+ end
33
+
34
+ describe "#gt" do
35
+ it "returns the > comparison for v" do
36
+ s.gt(7).should == Oedipus::Comparison::GT.new(7)
37
+ end
38
+ end
39
+
40
+ describe "#lt" do
41
+ it "returns the < comparison for v" do
42
+ s.lt(7).should == Oedipus::Comparison::LT.new(7)
43
+ end
44
+ end
45
+
46
+ describe "#gte" do
47
+ it "returns the >= comparison for v" do
48
+ s.gte(7).should == Oedipus::Comparison::GTE.new(7)
49
+ end
50
+ end
51
+
52
+ describe "#lte" do
53
+ it "returns the <= comparison for v" do
54
+ s.lte(7).should == Oedipus::Comparison::LTE.new(7)
55
+ end
56
+ end
57
+
58
+ describe "#between" do
59
+ context "with a range" do
60
+ it "returns the BETWEEN comparison for v" do
61
+ s.between(7..11).should == Oedipus::Comparison::Between.new(7..11)
62
+ end
63
+ end
64
+
65
+ context "with two bounds" do
66
+ it "returns the BETWEEN comparison for x and y" do
67
+ s.between(7, 11).should == Oedipus::Comparison::Between.new(7..11)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "#outside" do
73
+ context "with a range" do
74
+ it "returns the NOT BETWEEN comparison for v" do
75
+ s.outside(7..11).should == Oedipus::Comparison::Outside.new(7..11)
76
+ end
77
+ end
78
+
79
+ context "with two bounds" do
80
+ it "returns the NOT BETWEEN comparison for x and y" do
81
+ s.outside(7, 11).should == Oedipus::Comparison::Outside.new(7..11)
82
+ end
83
+ end
84
+ end
85
+
86
+ describe "#in" do
87
+ context "with an array" do
88
+ it "returns the IN comparison for v" do
89
+ s.in([1, 2, 3]).should == Oedipus::Comparison::In.new([1, 2, 3])
90
+ end
91
+ end
92
+
93
+ context "with a range" do
94
+ it "returns the IN comparison for v" do
95
+ s.in(1..3).should == Oedipus::Comparison::In.new([1, 2, 3])
96
+ end
97
+ end
98
+
99
+ context "with a variable arguments" do
100
+ it "returns the IN comparison for x, y, z" do
101
+ s.in(1, 2, 3).should == Oedipus::Comparison::In.new([1, 2, 3])
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#not_in" do
107
+ context "with an array" do
108
+ it "returns the NOT IN comparison for v" do
109
+ s.not_in([1, 2, 3]).should == Oedipus::Comparison::NotIn.new([1, 2, 3])
110
+ end
111
+ end
112
+
113
+ context "with a range" do
114
+ it "returns the NOT IN comparison for v" do
115
+ s.not_in(1..3).should == Oedipus::Comparison::NotIn.new([1, 2, 3])
116
+ end
117
+ end
118
+
119
+ context "with a variable arguments" do
120
+ it "returns the NOT IN comparison for x, y, z" do
121
+ s.not_in(1, 2, 3).should == Oedipus::Comparison::NotIn.new([1, 2, 3])
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+ ##
4
+ # Oedipus Sphinx 2 Search.
5
+ # Copyright © 2012 Chris Corbyn.
6
+ #
7
+ # See LICENSE file for details.
8
+ ##
9
+
10
+ require "spec_helper"
11
+
12
+ describe Oedipus::Comparison do
13
+ subject { Oedipus::Comparison }
14
+
15
+ describe "#of" do
16
+ context "with a comparison" do
17
+ it "returns the comparison" do
18
+ subject.of(
19
+ Oedipus::Comparison::Equal.new(7)
20
+ ).should == Oedipus::Comparison::Equal.new(7)
21
+ end
22
+ end
23
+
24
+ context "with a Fixnum" do
25
+ it "returns an Equal comparison" do
26
+ subject.of(7).should == Oedipus::Comparison::Equal.new(7)
27
+ end
28
+ end
29
+
30
+ context "with a Float" do
31
+ it "returns an Equal comparison" do
32
+ subject.of(7.2).should == Oedipus::Comparison::Equal.new(7.2)
33
+ end
34
+ end
35
+
36
+ context "with a BigDecimal" do
37
+ it "returns an Equal comparison" do
38
+ subject.of(BigDecimal("7.2")).should == Oedipus::Comparison::Equal.new(7.2)
39
+ end
40
+ end
41
+
42
+ context "with a Rational" do
43
+ it "returns an Equal comparison" do
44
+ subject.of(Rational("1/3")).should == Oedipus::Comparison::Equal.new(Rational("1/3").to_f)
45
+ end
46
+ end
47
+
48
+ context "with a String" do
49
+ it "returns an Equal comparison" do
50
+ subject.of("test").should == Oedipus::Comparison::Equal.new("test")
51
+ end
52
+ end
53
+
54
+ context "with a Symbol" do
55
+ it "returns an Equal comparison" do
56
+ subject.of(:test).should == Oedipus::Comparison::Equal.new(:test)
57
+ end
58
+ end
59
+
60
+ context "with a range" do
61
+ context "starting at -Infinity" do
62
+ context "inclusive" do
63
+ it "returns a LTE comparison" do
64
+ subject.of(-Float::INFINITY..10).should == Oedipus::Comparison::LTE.new(10)
65
+ end
66
+ end
67
+
68
+ context "exclusive" do
69
+ it "returns a LT comparison" do
70
+ subject.of(-Float::INFINITY...10).should == Oedipus::Comparison::LT.new(10)
71
+ end
72
+ end
73
+ end
74
+
75
+ context "ending at -Infinity" do
76
+ context "inclusive" do
77
+ it "returns a GTE comparison" do
78
+ subject.of(10..Float::INFINITY).should == Oedipus::Comparison::GTE.new(10)
79
+ end
80
+ end
81
+
82
+ context "exclusive" do
83
+ it "returns a GT comparison" do
84
+ subject.of(10...Float::INFINITY).should == Oedipus::Comparison::GT.new(10)
85
+ end
86
+ end
87
+ end
88
+
89
+ context "of real numbers" do
90
+ it "returns a BETWEEN comparison" do
91
+ subject.of(10..20).should == Oedipus::Comparison::Between.new(10..20)
92
+ end
93
+ end
94
+ end
95
+
96
+ context "with an array" do
97
+ it "returns an IN comparison" do
98
+ subject.of([1, 2, 3]).should == Oedipus::Comparison::In.new([1, 2, 3])
99
+ end
100
+ end
101
+
102
+ context "with an Enumerable type" do
103
+ it "returns an IN comparison" do
104
+ require 'set'
105
+ subject.of(Set[1, 2, 3]).should == Oedipus::Comparison::In.new([1, 2, 3])
106
+ end
107
+ end
108
+ end
109
+ end