query-interface-client 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c18cd4dae2c81dd2e352d5509607cc1905c0e01e
4
- data.tar.gz: 1b68f3bb6b2d722861b111d4237590840f0ec041
3
+ metadata.gz: dc69a17a6771188a3511438b38108507763bbf9f
4
+ data.tar.gz: 4eaa1e7bac65cbb3d7ebb6444ec0a8a0eef64689
5
5
  SHA512:
6
- metadata.gz: 3ab5f0827c2b0f95f2adf47ac32b5300cd37ba75930551fdc6fa0d73dcbf7f2c83d81a21aaf4a818e73f89eb74fd34c22ca728910d81d6b13637f3b03c6149e4
7
- data.tar.gz: c5f347f8779355906031dbf25aa546d992c53750f3090c061a15ce204118cab9a19d835f7a8a65f3ec3a1deba3215ef02f0a8e492bc00a2e0fc12264cb749415
6
+ metadata.gz: de3bc7968ba2c2c41b1f004b9bd746a97a9119a3d0a481d8e16fb27c46ac8847630ae93235a677cfff13a27200f98eebe750ee42be6e91a7192c8ed976e69c66
7
+ data.tar.gz: 9d25264e17db89eb376f2c5abec7276a2c965f5cf2a87c713f762ccdc07256db1af190f64a42541374f0992d14eead385359a56a4b4178109090fd952bf20910
@@ -77,27 +77,30 @@ module QueryInterface
77
77
  end
78
78
 
79
79
  def paginate(params={})
80
+ query = self.copy
80
81
  params = {page: 1, per_page: 10,}.merge(params)
81
- self.add_transformation(:paginate, params)
82
- raw = self.do_raw_query()
82
+ query.add_transformation(:paginate, params)
83
+ raw = query.do_raw_query()
83
84
  result = raw[:parsed_data][:data]
84
- objects = result[:objects].map { |h| self.instantiate(h) }
85
+ objects = result[:objects].map { |h| query.instantiate(h) }
85
86
  WillPaginate::Collection.create(params[:page], params[:per_page], result[:total]) do |pager|
86
87
  pager.replace objects
87
88
  end
88
89
  end
89
90
 
90
91
  def ids
91
- self.add_transformation(:map_ids)
92
- self.do_raw_query()[:parsed_data][:data]
92
+ query = self.copy
93
+ query.add_transformation(:map_ids)
94
+ query.do_raw_query()[:parsed_data][:data]
93
95
  end
94
96
 
95
97
  def count
96
98
  if self.result
97
99
  self.result.count
98
100
  else
99
- self.add_transformation(:count)
100
- r = self.do_raw_query()
101
+ query = self.copy
102
+ query.add_transformation(:count)
103
+ r = query.do_raw_query()
101
104
  r[:parsed_data][:data][:count]
102
105
  end
103
106
  end
@@ -140,8 +143,9 @@ module QueryInterface
140
143
  if self.result
141
144
  self.result.send(which)
142
145
  else
143
- self.add_transformation(which)
144
- self.do_query
146
+ query = self.copy
147
+ query.add_transformation(which)
148
+ query.do_query
145
149
  end
146
150
  end
147
151
 
@@ -1,7 +1,7 @@
1
1
  module QueryInterface
2
2
  module Client
3
3
 
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
 
6
6
  end
7
7
  end
@@ -118,6 +118,7 @@ describe QueryInterface::Client::LazyQuery do
118
118
  let(:transformations) {[transformation: :first, parameter: nil]}
119
119
  it "gets the first object via do_query" do
120
120
  query = subject.new(model)
121
+ query.should_receive(:copy).and_return(query)
121
122
  query.should_receive(:do_query)
122
123
  query.first
123
124
  query.transformations.should eq(self.transformations)
@@ -135,6 +136,7 @@ describe QueryInterface::Client::LazyQuery do
135
136
  let(:transformations) {[transformation: :last, parameter: nil]}
136
137
  it "gets the last object via do_query" do
137
138
  query = subject.new(model)
139
+ query.should_receive(:copy).and_return(query)
138
140
  query.should_receive(:do_query)
139
141
  query.last
140
142
  query.transformations.should eq(self.transformations)
@@ -184,6 +186,7 @@ describe QueryInterface::Client::LazyQuery do
184
186
 
185
187
  it "adds a map_ids transformation" do
186
188
  query = subject.new(model)
189
+ query.should_receive(:copy).and_return(query)
187
190
  query.stub!(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
188
191
  query.ids
189
192
  query.transformations.should eq(self.transformations)
@@ -191,6 +194,7 @@ describe QueryInterface::Client::LazyQuery do
191
194
 
192
195
  it "returns the data of the parsed query" do
193
196
  query = subject.new(model)
197
+ query.should_receive(:copy).and_return(query)
194
198
  query.should_receive(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
195
199
  query.ids.should eq([1, 2, 3])
196
200
  end
@@ -201,6 +205,7 @@ describe QueryInterface::Client::LazyQuery do
201
205
 
202
206
  it "adds a count transformation" do
203
207
  query = subject.new(model)
208
+ query.should_receive(:copy).and_return(query)
204
209
  query.should_receive(:do_raw_query).and_return({parsed_data: {data: {count: 42}}})
205
210
  query.count.should eq(42)
206
211
  query.transformations.should eq(self.transformations)
@@ -220,6 +225,7 @@ describe QueryInterface::Client::LazyQuery do
220
225
 
221
226
  it "adds a paginate transformation" do
222
227
  query = subject.new(model)
228
+ query.should_receive(:copy).and_return(query)
223
229
  objects = (1..10).to_a
224
230
  model.stub(:new).and_return(*objects)
225
231
  query.should_receive(:do_raw_query).and_return({parsed_data: {data: {objects: objects, total: 15}, errors: []}})
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Kopecky <andreas.kopecky@radarservices.com>
@@ -123,8 +123,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.0.3
126
+ rubygems_version: 2.0.5
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Client for the radar query interface
130
130
  test_files: []
131
+ has_rdoc: