axiom-do-adapter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +37 -0
  5. data/.rspec +4 -0
  6. data/.rvmrc +1 -0
  7. data/.travis.yml +35 -0
  8. data/CONTRIBUTING.md +11 -0
  9. data/Gemfile +10 -0
  10. data/Gemfile.devtools +57 -0
  11. data/Guardfile +23 -0
  12. data/LICENSE +20 -0
  13. data/README.md +26 -0
  14. data/Rakefile +5 -0
  15. data/TODO +0 -0
  16. data/axiom-do-adapter.gemspec +27 -0
  17. data/config/flay.yml +3 -0
  18. data/config/flog.yml +2 -0
  19. data/config/mutant.yml +3 -0
  20. data/config/reek.yml +115 -0
  21. data/config/yardstick.yml +2 -0
  22. data/lib/axiom-do-adapter.rb +4 -0
  23. data/lib/axiom/adapter/data_objects.rb +55 -0
  24. data/lib/axiom/adapter/data_objects/statement.rb +109 -0
  25. data/lib/axiom/adapter/data_objects/version.rb +12 -0
  26. data/lib/axiom/relation/gateway.rb +374 -0
  27. data/spec/rcov.opts +7 -0
  28. data/spec/shared/binary_relation_method_behaviour.rb +51 -0
  29. data/spec/shared/unary_relation_method_behaviour.rb +21 -0
  30. data/spec/spec_helper.rb +46 -0
  31. data/spec/support/config_alias.rb +3 -0
  32. data/spec/support/example_group_methods.rb +7 -0
  33. data/spec/support/ice_nine_config.rb +6 -0
  34. data/spec/unit/axiom/adapter/data_objects/class_methods/new_spec.rb +15 -0
  35. data/spec/unit/axiom/adapter/data_objects/read_spec.rb +66 -0
  36. data/spec/unit/axiom/adapter/data_objects/statement/class_methods/new_spec.rb +28 -0
  37. data/spec/unit/axiom/adapter/data_objects/statement/each_spec.rb +63 -0
  38. data/spec/unit/axiom/adapter/data_objects/statement/to_s_spec.rb +53 -0
  39. data/spec/unit/axiom/relation/gateway/class_methods/new_spec.rb +16 -0
  40. data/spec/unit/axiom/relation/gateway/difference_spec.rb +17 -0
  41. data/spec/unit/axiom/relation/gateway/drop_spec.rb +21 -0
  42. data/spec/unit/axiom/relation/gateway/each_spec.rb +86 -0
  43. data/spec/unit/axiom/relation/gateway/extend_spec.rb +29 -0
  44. data/spec/unit/axiom/relation/gateway/intersect_spec.rb +17 -0
  45. data/spec/unit/axiom/relation/gateway/join_spec.rb +44 -0
  46. data/spec/unit/axiom/relation/gateway/materialize_spec.rb +27 -0
  47. data/spec/unit/axiom/relation/gateway/optimize_spec.rb +23 -0
  48. data/spec/unit/axiom/relation/gateway/product_spec.rb +17 -0
  49. data/spec/unit/axiom/relation/gateway/project_spec.rb +21 -0
  50. data/spec/unit/axiom/relation/gateway/remove_spec.rb +21 -0
  51. data/spec/unit/axiom/relation/gateway/rename_spec.rb +21 -0
  52. data/spec/unit/axiom/relation/gateway/respond_to_spec.rb +29 -0
  53. data/spec/unit/axiom/relation/gateway/restrict_spec.rb +29 -0
  54. data/spec/unit/axiom/relation/gateway/reverse_spec.rb +21 -0
  55. data/spec/unit/axiom/relation/gateway/sort_by_spec.rb +29 -0
  56. data/spec/unit/axiom/relation/gateway/summarize_spec.rb +154 -0
  57. data/spec/unit/axiom/relation/gateway/take_spec.rb +21 -0
  58. data/spec/unit/axiom/relation/gateway/union_spec.rb +17 -0
  59. metadata +214 -0
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#each' do
7
+ subject { object.each { |tuple| yields << tuple } }
8
+
9
+ let(:header) { mock('Header') }
10
+ let(:reader) { mock('Reader') }
11
+ let(:tuple) { mock('Tuple') }
12
+ let(:adapter) { mock('Adapter') }
13
+ let(:relation) { mock('Relation') }
14
+ let!(:object) { described_class.new(adapter, relation) }
15
+ let(:yields) { [] }
16
+
17
+ context 'with an unmaterialized relation' do
18
+ let(:wrapper) { stub }
19
+
20
+ before do
21
+ adapter.stub!(:read).and_return(reader)
22
+
23
+ relation.stub!(:header).and_return(header)
24
+ relation.stub!(:materialized?).and_return(false)
25
+ relation.stub!(:each).and_return(relation)
26
+
27
+ wrapper.stub!(:each).and_yield(tuple)
28
+ Relation.stub!(:new).and_return(wrapper)
29
+ end
30
+
31
+ it_should_behave_like 'an #each method'
32
+
33
+ it 'yields each tuple' do
34
+ expect { subject }.to change { yields.dup }.
35
+ from([]).
36
+ to([ tuple ])
37
+ end
38
+
39
+ it 'passes in the relation to the adapter reader' do
40
+ adapter.should_receive(:read).with(relation)
41
+ subject
42
+ end
43
+
44
+ it 'passes in the relation header and reader to the wrapper constructor' do
45
+ Relation.should_receive(:new).with(header, reader)
46
+ subject
47
+ end
48
+ end
49
+
50
+ context 'with a materialized relation' do
51
+ before do
52
+ relation.stub!(:materialized?).and_return(true)
53
+
54
+ tuple = self.tuple
55
+
56
+ # I do not know a better way to mock this behaviour out and
57
+ # I'm pretty sure that rspec does not provide Enumerator helpers
58
+ relation.define_singleton_method(:each) do |&block|
59
+ if block
60
+ block.call(tuple)
61
+ self
62
+ else
63
+ to_enum
64
+ end
65
+ end
66
+ end
67
+
68
+ it_should_behave_like 'an #each method'
69
+
70
+ it 'yields each tuple' do
71
+ expect { subject }.to change { yields.dup }.
72
+ from([]).
73
+ to([ tuple ])
74
+ end
75
+
76
+ it 'does not create a reader' do
77
+ adapter.should_not_receive(:read)
78
+ subject
79
+ end
80
+
81
+ it 'does not create a wrapper' do
82
+ Relation.should_not_receive(:new)
83
+ subject
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#extend' do
7
+ subject { object.extend(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :extend => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { lambda { |context| } }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#extend' do
19
+ relation.should_receive(:extend).with(args)
20
+ subject
21
+ end
22
+
23
+ unless testing_block_passing_broken?
24
+ it 'forwards the block to relation#extend' do
25
+ relation.should_receive(:extend) { |&proc| proc.should equal(block) }
26
+ subject
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#intersect' do
7
+ subject { object.intersect(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :intersect }
13
+ let(:factory) { Algebra::Intersection }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#join' do
7
+ subject { object.join(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :join }
13
+ let(:factory) { Algebra::Join }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+
18
+ context 'when passed a block' do
19
+ subject { object.join(other) { |context| yields << context } }
20
+
21
+ let(:other_relation) { mock('Other Relation') }
22
+ let(:other) { described_class.new(adapter, other_relation) }
23
+ let(:gateway) { mock('Other Gateway') }
24
+ let(:join) { mock('Join', :restrict => gateway) }
25
+ let(:yields) { [] }
26
+
27
+ before do
28
+ Algebra::Join.stub!(:new).with(relation, other_relation).and_return(join)
29
+ end
30
+
31
+ it { should equal(gateway) }
32
+
33
+ it 'passes the relations to the join constructor' do
34
+ Algebra::Join.should_receive(:new).with(relation, other_relation)
35
+ subject
36
+ end
37
+
38
+ it 'passes the block to the join relation' do
39
+ context = mock('Context')
40
+ join.should_receive(:restrict).and_yield(context)
41
+ expect { subject }.to change { yields.dup }.from([]).to([ context ])
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#materialize' do
7
+ subject { object.materialize }
8
+
9
+ let(:header) { mock('Header') }
10
+ let(:directions) { mock('Directions') }
11
+ let(:adapter) { stub.as_null_object }
12
+ let(:relation) { mock('Relation', :header => header, :directions => directions, :materialized? => false) }
13
+ let!(:object) { described_class.new(adapter, relation) }
14
+ let(:materialized) { mock('Materialized') }
15
+
16
+ before do
17
+ Relation::Materialized.stub!(:new).and_return(materialized)
18
+ Relation.stub!(:new).and_return(stub.as_null_object)
19
+ end
20
+
21
+ it { should equal(materialized) }
22
+
23
+ it 'initializes the materialized relation with the header, tuples and directions' do
24
+ Relation::Materialized.should_receive(:new).with(header, [], directions)
25
+ subject
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#optimize' do
7
+ subject { object.optimize }
8
+
9
+ let(:adapter) { stub }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+
13
+ before do
14
+ relation.stub!(:optimize).and_return(relation)
15
+ end
16
+
17
+ it_should_behave_like 'a command method'
18
+
19
+ it 'forwards the message to relation#optimize' do
20
+ relation.should_receive(:optimize).with(no_args)
21
+ subject
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#product' do
7
+ subject { object.product(other) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation') }
11
+ let(:object) { described_class.new(adapter, relation) }
12
+ let(:operation) { :product }
13
+ let(:factory) { Algebra::Product }
14
+ let(:binary_relation) { mock(factory) }
15
+
16
+ it_should_behave_like 'a binary relation method'
17
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#project' do
7
+ subject { object.project(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :project => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#project' do
18
+ relation.should_receive(:project).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#remove' do
7
+ subject { object.remove(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :remove => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#remove' do
18
+ relation.should_receive(:remove).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#rename' do
7
+ subject { object.rename(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :rename => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#rename' do
18
+ relation.should_receive(:rename).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#respond_to?' do
7
+ subject { object.respond_to?(method) }
8
+
9
+ let(:relation) { mock('Relation', :header => stub) }
10
+ let(:object) { described_class.new(stub, relation) }
11
+
12
+ context 'with an unknown method' do
13
+ let(:method) { :unknown }
14
+
15
+ it { should be(false) }
16
+ end
17
+
18
+ context 'with a known method' do
19
+ let(:method) { :each }
20
+
21
+ it { should be(true) }
22
+ end
23
+
24
+ context 'with a known method in the relation' do
25
+ let(:method) { :header }
26
+
27
+ it { should be(true) }
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#restrict' do
7
+ subject { object.restrict(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :restrict => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { lambda { |context| } }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#restrict' do
19
+ relation.should_receive(:restrict).with(args)
20
+ subject
21
+ end
22
+
23
+ unless testing_block_passing_broken?
24
+ it 'forwards the block to relation#restrict' do
25
+ relation.should_receive(:restrict) { |_args, &proc| proc.should equal(block) }
26
+ subject
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#reverse' do
7
+ subject { object.reverse(args) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :reverse => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+
15
+ it_should_behave_like 'a unary relation method'
16
+
17
+ it 'forwards the arguments to relation#reverse' do
18
+ relation.should_receive(:reverse).with(args)
19
+ subject
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#sort_by' do
7
+ subject { object.sort_by(args, &block) }
8
+
9
+ let(:adapter) { mock('Adapter') }
10
+ let(:relation) { mock('Relation', :sort_by => response) }
11
+ let(:response) { mock('New Relation', :kind_of? => true) }
12
+ let!(:object) { described_class.new(adapter, relation) }
13
+ let(:args) { stub }
14
+ let(:block) { lambda { |context| } }
15
+
16
+ it_should_behave_like 'a unary relation method'
17
+
18
+ it 'forwards the arguments to relation#sort_by' do
19
+ relation.should_receive(:sort_by).with(args)
20
+ subject
21
+ end
22
+
23
+ unless testing_block_passing_broken?
24
+ it 'forwards the block to relation#sort_by' do
25
+ relation.should_receive(:sort_by) { |&proc| proc.should equal(block) }
26
+ subject
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'axiom/relation/gateway'
5
+
6
+ describe Relation::Gateway, '#summarize' do
7
+ let(:summarization) { mock('Summarization', :kind_of? => true) }
8
+ let(:adapter) { mock('Adapter') }
9
+ let(:relation) { mock('Relation', :summarize => summarization) }
10
+ let!(:object) { described_class.new(adapter, relation) }
11
+ let(:block) { lambda { |context| } }
12
+
13
+ context 'with no arguments' do
14
+ subject { object.summarize(&block) }
15
+
16
+ let(:gateway) { mock('New Gateway') }
17
+
18
+ before do
19
+ described_class.stub!(:new).and_return(gateway)
20
+ end
21
+
22
+ it { should equal(gateway) }
23
+
24
+ it 'forwards the default summarize_with relation to relation#summarize' do
25
+ relation.should_receive(:summarize) do |other|
26
+ other.should equal(TABLE_DEE)
27
+ end
28
+ subject
29
+ end
30
+
31
+ unless testing_block_passing_broken?
32
+ it 'forwards the block to relation#summarize' do
33
+ relation.should_receive(:summarize) do |_summarize_with, &proc|
34
+ proc.should equal(block)
35
+ end
36
+ subject
37
+ end
38
+ end
39
+
40
+ it 'initializes the gateway with the adapter and summarization' do
41
+ described_class.should_receive(:new).with(adapter, summarization)
42
+ subject
43
+ end
44
+ end
45
+
46
+ context 'with a header' do
47
+ subject { object.summarize(header, &block) }
48
+
49
+ let(:gateway) { mock('New Gateway') }
50
+ let(:header) { mock('Header') }
51
+
52
+ before do
53
+ described_class.stub!(:new).and_return(gateway)
54
+ end
55
+
56
+ it { should equal(gateway) }
57
+
58
+ it 'forwards the header to relation#summarize' do
59
+ relation.should_receive(:summarize) do |other|
60
+ other.should equal(header)
61
+ end
62
+ subject
63
+ end
64
+
65
+ unless testing_block_passing_broken?
66
+ it 'forwards the block to relation#summarize' do
67
+ relation.should_receive(:summarize) do |_summarize_with, &proc|
68
+ proc.should equal(block)
69
+ end
70
+ subject
71
+ end
72
+ end
73
+
74
+ it 'initializes the gateway with the adapter and summarization' do
75
+ described_class.should_receive(:new).with(adapter, summarization)
76
+ subject
77
+ end
78
+ end
79
+
80
+ context 'when summarize_with has the same adapter' do
81
+ subject { object.summarize(other, &block) }
82
+
83
+ let(:header) { mock('Header') }
84
+ let(:other_relation) { mock('Other Relation', :header => header) }
85
+ let!(:other) { described_class.new(adapter, other_relation) }
86
+ let(:gateway) { mock('New Gateway') }
87
+
88
+ before do
89
+ described_class.stub!(:new).and_return(gateway)
90
+ end
91
+
92
+ it { should equal(gateway) }
93
+
94
+ it 'forwards the other relation to relation#summarize' do
95
+ relation.should_receive(:summarize) do |other|
96
+ other.should equal(other_relation)
97
+ end
98
+ subject
99
+ end
100
+
101
+ unless testing_block_passing_broken?
102
+ it 'forwards the block to relation#summarize' do
103
+ relation.should_receive(:summarize) do |_summarize_with, &proc|
104
+ proc.should equal(block)
105
+ end
106
+ subject
107
+ end
108
+ end
109
+
110
+ it 'initializes the gateway with the adapter and summarization' do
111
+ described_class.should_receive(:new).with(adapter, summarization)
112
+ subject
113
+ end
114
+ end
115
+
116
+ context 'with a relation' do
117
+ subject { object.summarize(summarize_with, &block) }
118
+
119
+ let(:context_header) { mock('Context Header') }
120
+ let(:header) { mock('Header', :- => context_header) }
121
+ let(:summarize_header) { mock('Summarize With Header') }
122
+ let(:summarize_with) { mock('Other Relation', :header => summarize_header) }
123
+ let(:functions) { mock('Functions') }
124
+ let(:context) { mock('Context', :functions => functions) }
125
+
126
+ before do
127
+ relation.stub!(:header).and_return(header)
128
+ Algebra::Summarization.stub!(:new).and_return(summarization)
129
+ Evaluator::Context.stub!(:new).and_return(context)
130
+ end
131
+
132
+ it { should equal(summarization) }
133
+
134
+ it 'gets the context header' do
135
+ header.should_receive(:-).with(summarize_header)
136
+ subject
137
+ end
138
+
139
+ it 'passes the context header into the context' do
140
+ Evaluator::Context.should_receive(:new).with(context_header)
141
+ subject
142
+ end
143
+
144
+ it 'forwards the block to the context' do
145
+ Evaluator::Context.stub!(:new) { |_header, proc| proc.should equal(block) }.and_return(context)
146
+ subject
147
+ end
148
+
149
+ it 'initializes the summarization with the gateway, the relation and the functions' do
150
+ Algebra::Summarization.should_receive(:new).with(object, summarize_with, functions)
151
+ subject
152
+ end
153
+ end
154
+ end