hoodoo 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGUwNzBiZDE0NDVjYjljNDM0MzNjYzYzMjYxMWY0MzhhYmY4NTI2OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmUxY2FiOWQzMDY1ZmEwZGM1NzYxM2YzNDVjYzFhNWE2N2FmNDZmNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjJkZGJkMTM4MmM5ZWNhYmQxOWI3Y2JkYzdmN2I3OGFjZTU4OGQ4MDY3MDI0
|
10
|
+
MWYwZGI5MDIzZDNmYjI2ZTJiNzE4ZmU3MjNkZDM5YjA0ZjU1ODA1OTM1MzA0
|
11
|
+
OWNmYjFlNjRlZTVjZThiMWIxNTJlZTA1NzU0MTQ1Y2U5NDFhMTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDdmOTMyNTVhMGZiZDAxMzkyNDE1OGQ3MTIxNTJiMzViZWQ2MGJhMTUzYjRh
|
14
|
+
MGEwMWM1M2EyZTI3MWVlZTA5ZTE4ZjkwN2M5OGRiZDBlMTY3NjE3M2JhNTYw
|
15
|
+
NWQ5ZTYyN2EzODI2MWVmODBmMmQ4YzMyMDMyZjQ0OTc1MDdjMGI=
|
@@ -144,27 +144,6 @@ module Hoodoo
|
|
144
144
|
model.extend( ClassMethods )
|
145
145
|
end
|
146
146
|
|
147
|
-
# Returns a String containing the specified +model_klass+'s attribute
|
148
|
-
# names considered as column names, escaped by the in-use database
|
149
|
-
# adaptor and joined into with commas.
|
150
|
-
#
|
151
|
-
# +model_klass+:: Class which responds to <tt>#attribute_names</tt>.
|
152
|
-
#
|
153
|
-
def self.sanitised_column_string( model_klass )
|
154
|
-
self.sanitised_column_string_for( model_klass.attribute_names )
|
155
|
-
end
|
156
|
-
|
157
|
-
# As ::sanitised_column_string but takes the array of attribute or
|
158
|
-
# column names directly.
|
159
|
-
#
|
160
|
-
# +attribute_array+:: Array of column names, as Strings or Symbols.
|
161
|
-
#
|
162
|
-
def self.sanitised_column_string_for( attribute_array )
|
163
|
-
attribute_array.map do | c |
|
164
|
-
ActiveRecord::Base.connection.quote_column_name( c )
|
165
|
-
end.join( ',' )
|
166
|
-
end
|
167
|
-
|
168
147
|
# Collection of class methods that get defined on an including class via
|
169
148
|
# Hoodoo::ActiveRecord::Dated::included.
|
170
149
|
#
|
@@ -392,7 +371,7 @@ module Hoodoo
|
|
392
371
|
#
|
393
372
|
def quoted_column_name_string( unquoted_column_names: nil )
|
394
373
|
unquoted_column_names ||= self.attribute_names()
|
395
|
-
unquoted_column_names
|
374
|
+
unquoted_column_names = unquoted_column_names + [ 'id' ] unless unquoted_column_names.include?( 'id' )
|
396
375
|
|
397
376
|
return self.quoted_column_names( unquoted_column_names ).join( ',' )
|
398
377
|
end
|
@@ -413,8 +392,8 @@ module Hoodoo
|
|
413
392
|
primary_key_index = unquoted_column_names.index( 'id' )
|
414
393
|
|
415
394
|
if primary_key_index.nil?
|
416
|
-
unquoted_column_names
|
417
|
-
primary_key_index
|
395
|
+
unquoted_column_names = unquoted_column_names + [ 'id' ]
|
396
|
+
primary_key_index = unquoted_column_names.count - 1
|
418
397
|
end
|
419
398
|
|
420
399
|
quoted_column_names = self.quoted_column_names( unquoted_column_names )
|
@@ -152,7 +152,7 @@ module Hoodoo
|
|
152
152
|
# Returns a found model instance or +nil+ for no match.
|
153
153
|
#
|
154
154
|
def acquire( ident )
|
155
|
-
extra_fields = self.
|
155
|
+
extra_fields = self.acquired_with()
|
156
156
|
|
157
157
|
id_fields = [ :id ] + extra_fields
|
158
158
|
id_fields.each do | field |
|
@@ -270,12 +270,28 @@ module Hoodoo
|
|
270
270
|
|
271
271
|
# Describe the list of model fields _in_ _addition_ _to_ +id+ which
|
272
272
|
# are to be used to "find-by-identifier" through calls #acquire and
|
273
|
-
# #acquire_in. See those for more details.
|
273
|
+
# #acquire_in. See those methods for more details.
|
274
|
+
#
|
275
|
+
# Fields will be searched in the order listed. If duplicate items are
|
276
|
+
# present, the first occurrence is kept and the rest are removed.
|
274
277
|
#
|
275
278
|
# *args:: One or more field names as Strings or Symbols.
|
276
279
|
#
|
280
|
+
# See also: #acquired_with
|
281
|
+
#
|
277
282
|
def acquire_with( *args )
|
278
|
-
self.nz_co_loyalty_hoodoo_show_id_fields = args
|
283
|
+
self.nz_co_loyalty_hoodoo_show_id_fields = args.map( & :to_s ).uniq!()
|
284
|
+
end
|
285
|
+
|
286
|
+
# Return the list of model fields _in_ _addition_ _to_ +id+ which
|
287
|
+
# are being used to "find-by-identifier" through calls to #acquire
|
288
|
+
# and #acquire_in. The returned Array contains de-duplicated String
|
289
|
+
# values only.
|
290
|
+
#
|
291
|
+
# See also: #acquire_with
|
292
|
+
#
|
293
|
+
def acquired_with
|
294
|
+
self.nz_co_loyalty_hoodoo_show_id_fields || []
|
279
295
|
end
|
280
296
|
|
281
297
|
# Generate an ActiveRecord::Relation instance which can be used to
|
data/lib/hoodoo/version.rb
CHANGED
@@ -20,7 +20,7 @@ describe Hoodoo::ActiveRecord::Finder do
|
|
20
20
|
include Hoodoo::ActiveRecord::Finder
|
21
21
|
|
22
22
|
self.primary_key = :id
|
23
|
-
acquire_with :uuid, :code
|
23
|
+
acquire_with :uuid, :code, :uuid # Deliberate duplication
|
24
24
|
|
25
25
|
# These forms follow quite closely the RDoc comments in
|
26
26
|
# the finder.rb source.
|
@@ -238,6 +238,15 @@ describe Hoodoo::ActiveRecord::Finder do
|
|
238
238
|
@session = @interaction.context.session
|
239
239
|
end
|
240
240
|
|
241
|
+
it 'knowns how to acquire' do
|
242
|
+
|
243
|
+
# Note the corresponding 'acquire_with' used Symbols and had a
|
244
|
+
# duplicated entry - we expect Strings and no duplicates here.
|
245
|
+
#
|
246
|
+
expect( RSpecModelFinderTest.acquired_with() ).to eq( [ 'uuid', 'code' ] )
|
247
|
+
|
248
|
+
end
|
249
|
+
|
241
250
|
it 'finds with secure scopes from the class' do
|
242
251
|
@session.scoping = { :authorised_uuids => [ 'uuid 1' ], :authorised_code => 'code 1' }
|
243
252
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|