pod4 0.9.0 → 0.9.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 +5 -5
- data/.hgtags +1 -0
- data/lib/pod4/nebulous_interface.rb +42 -8
- data/lib/pod4/version.rb +1 -1
- data/spec/common/nebulous_interface_spec.rb +65 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2136af8ee4ba964aecab03dc618b2573e3b2d13883d3ab6965db115922a6ed67
|
4
|
+
data.tar.gz: 485443950826a519387cf740a0e6b7d8ebd3b3fa747e9fb8202f31e95f991362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa2d550a2c50e9ec82a77e786b00b3f4250356964f946eb3a5235aecd0e76bc464f17176669baf40054db788fb81347c545ce2ce014d5459fadb9aceac1822b0
|
7
|
+
data.tar.gz: cb2081a8903ffd66c2d67e98162875101da19480390ffb795042099f7352d5a3ef7b847ac59bc439113cf369d5ef0dc22269be38a481b92fd6e69e95824b2112
|
data/.hgtags
CHANGED
@@ -50,9 +50,25 @@ module Pod4
|
|
50
50
|
# success verb. If that's not true, then you will have to override #create and sort this out
|
51
51
|
# yourself.
|
52
52
|
#
|
53
|
-
#
|
53
|
+
# Note that all values are returned as strings; there is no typecasting. This is a given
|
54
54
|
# limitation for Nebulous as a whole.
|
55
55
|
#
|
56
|
+
# Calls to create, update and delete avoid (for obvious reasons) Nebulous' Redis cache if
|
57
|
+
# present. read and list use it. The interface methods take an extra options hash to control
|
58
|
+
# this, which, of course, Pod4::Model does not know about. If you want to enable a non-cached
|
59
|
+
# read in your model, it will need a method something like this:
|
60
|
+
#
|
61
|
+
# def read_no_cache
|
62
|
+
# r = interface.read(@model_id, caching: false)
|
63
|
+
#
|
64
|
+
# if r.empty?
|
65
|
+
# add_alert(:error, "Record ID '#@model_id' not found on the data source")
|
66
|
+
# else
|
67
|
+
# map_to_model(r)
|
68
|
+
# run_validation(:read)
|
69
|
+
# @model_status = :okay if @model_status == :empty
|
70
|
+
# end
|
71
|
+
#
|
56
72
|
class NebulousInterface < Interface
|
57
73
|
|
58
74
|
attr_reader :id_fld
|
@@ -176,14 +192,20 @@ module Pod4
|
|
176
192
|
# Returns an array of Octothorpes, or an empty array if the responder could not make any
|
177
193
|
# records out of our message.
|
178
194
|
#
|
179
|
-
|
195
|
+
# Note that the `opts` hash is not part of the protocol supported by Pod4::Model. If you want
|
196
|
+
# to make use of it, you will have to write your own method for that. Supported keys:
|
197
|
+
#
|
198
|
+
# * caching: true if you want to use redis caching (defaults to true)
|
199
|
+
#
|
200
|
+
def list(selection=nil, opts={})
|
180
201
|
sel =
|
181
202
|
case selection
|
182
203
|
when Array, Hash, Octothorpe then param_string(:list, selection)
|
183
204
|
else selection
|
184
205
|
end
|
185
206
|
|
186
|
-
|
207
|
+
caching = opts[:caching].nil? ? true : !!opts[:caching]
|
208
|
+
send_message( verb_for(:list), sel, caching )
|
187
209
|
@response.body.is_a?(Array) ? @response.body.map{|e| Octothorpe.new e} : []
|
188
210
|
|
189
211
|
rescue => e
|
@@ -192,14 +214,14 @@ module Pod4
|
|
192
214
|
|
193
215
|
|
194
216
|
##
|
195
|
-
# Pass a parameter string or an array as the record. returns the ID
|
217
|
+
# Pass a parameter string or an array as the record. returns the ID. We assume that the
|
196
218
|
# response to the create message returns the ID as the parameter part of the success verb. If
|
197
219
|
# that's not true, then you will have to override #create and sort this out yourself.
|
198
220
|
#
|
199
221
|
def create(record)
|
200
222
|
raise ArgumentError, 'create takes a Hash or an Octothorpe' unless hashy?(record)
|
201
223
|
|
202
|
-
send_message( verb_for(:create), param_string(:create, record) )
|
224
|
+
send_message( verb_for(:create), param_string(:create, record), false )
|
203
225
|
@response.params
|
204
226
|
|
205
227
|
rescue => e
|
@@ -212,10 +234,18 @@ module Pod4
|
|
212
234
|
#
|
213
235
|
# The actual parameters passed to nebulous depend on how you #set_verb
|
214
236
|
#
|
215
|
-
|
237
|
+
# Note that the `opts` hash is not part of the protocol supported by Pod4::Model. If you want
|
238
|
+
# to make use of it, you will have to write your own method for that. Supported keys:
|
239
|
+
#
|
240
|
+
# * caching: true if you want to use redis caching (defaults to true)
|
241
|
+
#
|
242
|
+
def read(id, opts={})
|
216
243
|
raise ArgumentError, 'You must pass an ID to read' unless id
|
217
244
|
|
218
|
-
|
245
|
+
caching = opts[:caching].nil? ? true : !!opts[:caching]
|
246
|
+
send_message( verb_for(:read),
|
247
|
+
param_string(:read, nil, id),
|
248
|
+
caching )
|
219
249
|
|
220
250
|
Octothorpe.new( @response.body.is_a?(Hash) ? @response.body : {} )
|
221
251
|
end
|
@@ -258,12 +288,16 @@ module Pod4
|
|
258
288
|
#
|
259
289
|
# @interface.clearing_cache.read(14)
|
260
290
|
#
|
291
|
+
# Note that there is no guarantee that the request that clears the cache is actually the one
|
292
|
+
# you chain after (if multiple model instances are running against the same interface instance)
|
293
|
+
# but for the instance that calls `clearing_cache`, this is not important.
|
294
|
+
#
|
261
295
|
def clearing_cache
|
262
296
|
@clear_cache = true
|
263
297
|
self
|
264
298
|
end
|
265
299
|
|
266
|
-
|
300
|
+
|
267
301
|
##
|
268
302
|
# Bonus method: send an arbitrary Nebulous message to the target and return the response object.
|
269
303
|
#
|
data/lib/pod4/version.rb
CHANGED
@@ -21,6 +21,13 @@ require_relative 'shared_examples_for_interface'
|
|
21
21
|
#
|
22
22
|
class FakeRequester
|
23
23
|
|
24
|
+
# Helper to record the first message sent to us.
|
25
|
+
class << self
|
26
|
+
def clear_method; @@method = nil; end
|
27
|
+
def set_method(x); @@method ||= x; end
|
28
|
+
def method; @@method; end
|
29
|
+
end
|
30
|
+
|
24
31
|
def initialize(data={}); @data = data; end
|
25
32
|
|
26
33
|
##
|
@@ -35,6 +42,13 @@ class FakeRequester
|
|
35
42
|
request = NebulousStomp::Request.new(target, requestmsg)
|
36
43
|
request.stomp_handler = stomphandler
|
37
44
|
|
45
|
+
# We need to know which send method was called. Note that #send calls #send_no_cache, so we
|
46
|
+
# record the first method called.
|
47
|
+
class << request
|
48
|
+
def send(*args); FakeRequester.set_method :send; super; end
|
49
|
+
def send_no_cache(*args); FakeRequester.set_method :send_no_cache; super; end
|
50
|
+
end
|
51
|
+
|
38
52
|
hash[:inReplyTo] = request.message.reply_id
|
39
53
|
responsemsg = NebulousStomp::Message.new hash
|
40
54
|
stomphandler.insert_fake(responsemsg)
|
@@ -162,9 +176,11 @@ describe "NebulousInterface" do
|
|
162
176
|
3 => {id: 3, name: 'Betty', price: 3.33} }
|
163
177
|
end
|
164
178
|
|
179
|
+
let(:fake) { FakeRequester.new(data) }
|
180
|
+
|
165
181
|
let(:interface) do
|
166
182
|
init_nebulous
|
167
|
-
nebulous_interface_class.new(
|
183
|
+
nebulous_interface_class.new(fake)
|
168
184
|
end
|
169
185
|
|
170
186
|
|
@@ -197,6 +213,12 @@ describe "NebulousInterface" do
|
|
197
213
|
expect( interface.read(id).to_h ).to include ot.to_h
|
198
214
|
end
|
199
215
|
|
216
|
+
it 'creates a non-caching request' do
|
217
|
+
FakeRequester.clear_method
|
218
|
+
id = interface.create(ot)
|
219
|
+
expect( FakeRequester.method ).to eq :send_no_cache
|
220
|
+
end
|
221
|
+
|
200
222
|
end
|
201
223
|
##
|
202
224
|
|
@@ -216,11 +238,22 @@ describe "NebulousInterface" do
|
|
216
238
|
expect( interface.read(99) ).to be_empty
|
217
239
|
end
|
218
240
|
|
241
|
+
it 'creates a caching request' do
|
242
|
+
FakeRequester.clear_method
|
243
|
+
id = interface.read(1)
|
244
|
+
expect( FakeRequester.method ).to eq :send
|
245
|
+
end
|
246
|
+
|
247
|
+
it "creates a non-caching request when passed an option" do
|
248
|
+
FakeRequester.clear_method
|
249
|
+
id = interface.read(1, caching: false)
|
250
|
+
expect( FakeRequester.method ).to eq :send_no_cache
|
251
|
+
end
|
252
|
+
|
219
253
|
end
|
220
254
|
##
|
221
255
|
|
222
256
|
|
223
|
-
|
224
257
|
describe '#list' do
|
225
258
|
|
226
259
|
it 'has an optional selection parameter, a hash' do
|
@@ -250,6 +283,19 @@ describe "NebulousInterface" do
|
|
250
283
|
expect( interface.list ).to eq([])
|
251
284
|
end
|
252
285
|
|
286
|
+
it 'creates a caching request' do
|
287
|
+
FakeRequester.clear_method
|
288
|
+
interface.list(name: 'Fred')
|
289
|
+
expect( FakeRequester.method ).to eq :send
|
290
|
+
end
|
291
|
+
|
292
|
+
it "creates a non-caching request when passed an option" do
|
293
|
+
FakeRequester.clear_method
|
294
|
+
interface.list({name: 'Fred'}, caching: false)
|
295
|
+
expect( FakeRequester.method ).to eq :send_no_cache
|
296
|
+
end
|
297
|
+
|
298
|
+
|
253
299
|
end
|
254
300
|
##
|
255
301
|
|
@@ -265,6 +311,15 @@ describe "NebulousInterface" do
|
|
265
311
|
expect( interface.read(id).to_h ).to include(rec)
|
266
312
|
end
|
267
313
|
|
314
|
+
it 'creates a non-caching request' do
|
315
|
+
i = id # creates a request, so get it done now
|
316
|
+
rec = {price: 99.99}
|
317
|
+
|
318
|
+
FakeRequester.clear_method
|
319
|
+
interface.update(i, rec)
|
320
|
+
expect( FakeRequester.method ).to eq :send_no_cache
|
321
|
+
end
|
322
|
+
|
268
323
|
end
|
269
324
|
##
|
270
325
|
|
@@ -288,6 +343,14 @@ describe "NebulousInterface" do
|
|
288
343
|
expect( list_contains(id) ).to be_falsy
|
289
344
|
end
|
290
345
|
|
346
|
+
it 'creates a non-caching request' do
|
347
|
+
i = id # creates a request, so get it done now
|
348
|
+
|
349
|
+
FakeRequester.clear_method
|
350
|
+
interface.delete(i)
|
351
|
+
expect( FakeRequester.method ).to eq :send_no_cache
|
352
|
+
end
|
353
|
+
|
291
354
|
end
|
292
355
|
##
|
293
356
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pod4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devnull
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.7.3
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Totally not an ORM
|