query-interface-client 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/lib/query-interface-client/resource.rb +9 -0
- data/lib/query-interface-client/version.rb +1 -1
- data/spec/lib/lazy_query_spec.rb +21 -21
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeee92f6abcc5feadfe736a221026538f7051135
|
4
|
+
data.tar.gz: e6ce1dbe30515ce5d940afd55755039705b63ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1716f5e0fbad420ac7ab614f4522063452b00f66efac17a172aaae94fc99219311f4c8e876bfe128b20c3d1eb67ec970ed1808b7174ea5eecfc601e97e33ffe6
|
7
|
+
data.tar.gz: b2d38e50e12f0c4de3487a8674c87d2fa4f60f02cee8bac6c770b558a38d5becd1ed8fde8500d1ef6a698c97a3390e33483f67b0870dc81d4bf8c1b38c884aeb
|
@@ -17,6 +17,15 @@ module QueryInterface::Client
|
|
17
17
|
def query
|
18
18
|
LazyQuery.new(self)
|
19
19
|
end
|
20
|
+
|
21
|
+
def association(name, class_name: nil, dataset: nil)
|
22
|
+
dataset ||= name
|
23
|
+
define_method(name) do
|
24
|
+
klass = (class_name || name.to_s.singularize.camelize).constantize
|
25
|
+
self.class.query.instance(self.id).context(dataset, klass)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
end
|
21
30
|
|
22
31
|
end
|
data/spec/lib/lazy_query_spec.rb
CHANGED
@@ -114,39 +114,39 @@ describe QueryInterface::Client::LazyQuery do
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
context
|
118
|
-
|
119
|
-
it "gets the first object via do_query" do
|
117
|
+
context 'first' do
|
118
|
+
it 'gets the first object' do
|
120
119
|
query = subject.new(model)
|
121
|
-
|
122
|
-
query.should_receive(:
|
123
|
-
query.first
|
124
|
-
query.transformations.should eq(self.transformations)
|
120
|
+
result = double('result')
|
121
|
+
query.should_receive(:one).with(:first).and_return(result)
|
122
|
+
query.first.should be(result)
|
125
123
|
end
|
124
|
+
end
|
126
125
|
|
127
|
-
|
126
|
+
context 'last' do
|
127
|
+
it 'gets the last object' do
|
128
128
|
query = subject.new(model)
|
129
|
-
|
130
|
-
query.
|
131
|
-
query.
|
129
|
+
result = double('result')
|
130
|
+
query.should_receive(:one).with(:last).and_return(result)
|
131
|
+
query.last.should be(result)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
-
context
|
136
|
-
|
137
|
-
it "gets the last object via do_query" do
|
135
|
+
context 'one' do
|
136
|
+
it 'gets one object' do
|
138
137
|
query = subject.new(model)
|
138
|
+
result = double('result')
|
139
139
|
query.should_receive(:copy).and_return(query)
|
140
|
-
query.should_receive(:do_query)
|
141
|
-
query.
|
142
|
-
query.
|
140
|
+
query.should_receive(:do_query).and_return(result)
|
141
|
+
query.result.should be_nil
|
142
|
+
query.send(:one, :anyone).should be(result)
|
143
|
+
query.transformations.should eq([{transformation: :anyone, parameter: nil}])
|
143
144
|
end
|
144
|
-
|
145
145
|
it "uses the cached result" do
|
146
146
|
query = subject.new(model)
|
147
147
|
query.result = ["a", "b", "c"]
|
148
|
-
query.should_not_receive(:
|
149
|
-
query.
|
148
|
+
query.should_not_receive(:do_query)
|
149
|
+
query.first.should eq("a")
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -187,7 +187,7 @@ describe QueryInterface::Client::LazyQuery do
|
|
187
187
|
it "adds a map_ids transformation" do
|
188
188
|
query = subject.new(model)
|
189
189
|
query.should_receive(:copy).and_return(query)
|
190
|
-
query.stub
|
190
|
+
query.stub(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
|
191
191
|
query.ids
|
192
192
|
query.transformations.should eq(self.transformations)
|
193
193
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query-interface-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Kopecky <andreas.kopecky@radarservices.com>
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-01-
|
13
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: her
|
@@ -128,4 +128,3 @@ signing_key:
|
|
128
128
|
specification_version: 4
|
129
129
|
summary: Client for the radar query interface
|
130
130
|
test_files: []
|
131
|
-
has_rdoc:
|