hoodoo 2.12.2 → 2.12.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97098d14a63ca3169567bec32d623914a8e04389c0b26a1c513ccfcd3069e101
4
- data.tar.gz: 0d673e879ca169f1dbcecd0d1c03bba5c8ec138f377abe99fc7aeccb3c39713d
3
+ metadata.gz: 430542c918e33830c23d09b1d4d6116f9d948bdca2d43f60c7b65c3a6d8be4f9
4
+ data.tar.gz: add79127d4fcc1ffa7a99a83c59bcdc47f6a766ce27c96fe3bd9f18f07874f8e
5
5
  SHA512:
6
- metadata.gz: a626927fcbd049c377698fe423550c78cd2feaf1225a54281e63dcc16cfa61093f7d03fbadfa01ef9739ca6987e6a1737fc0e29460a0734ee01536311479dd27
7
- data.tar.gz: 056a00f6fb6e7d171a3228d20e931f27e4e95aad9c5813dc91999666e1472b2f379964d87edf34e40adb2bfcb0692bd33fa0db091a6244a25c35b57297abde1e
6
+ metadata.gz: 1464c30acc087565f5c609ce1fbf6f9048dd9c3f995f2094ecdf7e6328b43d2c952e013feec8550ba253c820f0fd70946d52b40e1a57a2ecdf98138ba4a8a0a0
7
+ data.tar.gz: 5bfbf36ce4b624de24ef07bd64ba12462e471e3755ee23ce891370535e63382b986efdd2716a7caf25d365d36e8a800cad46c371935d59dbaf9384210b56099b
@@ -9,6 +9,8 @@
9
9
  # 15-Dec-2014 (ADH): Created.
10
10
  ########################################################################
11
11
 
12
+ require 'pp'
13
+
12
14
  module Hoodoo
13
15
  module Communicators
14
16
 
@@ -151,7 +153,7 @@ module Hoodoo
151
153
  begin
152
154
  communicator.communicate( object )
153
155
  rescue => exception
154
- handle_exception( exception, communicator )
156
+ handle_exception( exception, communicator, object )
155
157
  end
156
158
 
157
159
  else
@@ -333,6 +335,7 @@ module Hoodoo
333
335
  #
334
336
  loop do
335
337
 
338
+ obj = nil
336
339
  # Exception handler block.
337
340
  #
338
341
  begin
@@ -342,20 +345,23 @@ module Hoodoo
342
345
  #
343
346
  loop do
344
347
  entry = work_queue.shift() # ".shift" => FIFO, ".pop" would be LIFO
348
+ obj = nil
345
349
 
346
350
  if entry.terminate?
347
351
  ::Thread.exit
348
352
  elsif entry.sync?
353
+
349
354
  sync_queue << :sync
350
355
  elsif entry.dropped?
351
356
  communicator.dropped( entry.dropped )
352
357
  else
358
+ obj = entry.payload
353
359
  communicator.communicate( entry.payload )
354
360
  end
355
361
  end
356
362
 
357
363
  rescue => exception
358
- handle_exception( exception, communicator )
364
+ handle_exception( exception, communicator, obj )
359
365
 
360
366
  end
361
367
  end
@@ -453,12 +459,14 @@ module Hoodoo
453
459
  #
454
460
  # +exception+:: Exception (or Exception subclass) instance to print.
455
461
  # +communicator+:: Communicator instance that raised the exception.
462
+ # +obj+:: Parameter passed to the communicator subclass instance
463
+ # #communicate methods
456
464
  #
457
- def handle_exception( exception, communicator )
465
+ def handle_exception( exception, communicator, obj )
458
466
  begin
459
467
  report = "Communicator class #{ communicator.class.name } raised exception '#{ exception }': #{ exception.backtrace }"
460
468
  $stderr.puts( report )
461
-
469
+ pp( obj, $stderr )
462
470
  rescue
463
471
  # If the above fails then everything else is probably about to
464
472
  # collapse, but optimistically try to ignore the error and keep
@@ -90,12 +90,16 @@ module Hoodoo
90
90
  # were used to create the Session under which the
91
91
  # resource instance was created. Absent if omitted.
92
92
  #
93
+ # +updated_at+:: Optional Date/Time of instance update. This is a Ruby
94
+ # DateTime instance or similar, _NOT_ a string!
95
+ #
93
96
  def self.render( data,
94
97
  uuid = nil,
95
98
  created_at = nil,
96
99
  language = 'en-nz',
97
- created_by = nil )
98
-
100
+ created_by = nil,
101
+ updated_at = nil
102
+ )
99
103
  target = {}
100
104
  data = data || {}
101
105
 
@@ -126,6 +130,7 @@ module Hoodoo
126
130
  'created_at' => Hoodoo::Utilities.standard_datetime( created_at.to_datetime )
127
131
  } )
128
132
 
133
+ target[ 'updated_at' ] = Hoodoo::Utilities.standard_datetime( updated_at.to_datetime ) unless updated_at.nil?
129
134
  target[ 'created_by' ] = created_by unless created_by.nil?
130
135
  target[ 'language' ] = language if self.is_internationalised?()
131
136
 
@@ -167,6 +172,9 @@ module Hoodoo
167
172
  # +created_at+:: Same as the +created_at+ parameter to ::render, except
168
173
  # mandatory.
169
174
  #
175
+ # +updated_at+:: Optional value expressing the time the resource was last
176
+ # updated.
177
+ #
170
178
  # +created_by+:: Optional fingerprint of the Caller whose credentials
171
179
  # were used to create the Session under which the
172
180
  # resource instance was created.
@@ -194,13 +202,14 @@ module Hoodoo
194
202
  def self.render_in( context, data, options = {} )
195
203
  uuid = options[ :uuid ]
196
204
  created_at = options[ :created_at ]
205
+ updated_at = options[ :updated_at ]
197
206
  created_by = options[ :created_by ]
198
207
  language = options[ :language ] || context.request.locale
199
208
  secured_with = options[ :secured_with ]
200
209
  embeds = options[ :embeds ]
201
210
  references = options[ :references ]
202
211
 
203
- target = self.render( data, uuid, created_at, language, created_by )
212
+ target = self.render( data, uuid, created_at, language, created_by, updated_at )
204
213
 
205
214
  if defined?( ::ActiveRecord ) && secured_with.is_a?( ::ActiveRecord::Base )
206
215
  result_hash = {}
@@ -251,6 +260,9 @@ module Hoodoo
251
260
  created_by = data[ :created_by ]
252
261
  common_fields[ 'created_by' ] = created_by unless created_by.nil?
253
262
 
263
+ updated_at = data[ :updated_at ]
264
+ common_fields[ 'updated_at' ] = updated_at unless updated_at.nil?
265
+
254
266
  if self.is_internationalised?
255
267
  common_fields[ 'internationalised' ] = data[ 'internationalised' ]
256
268
  Hoodoo::Presenters::CommonResourceFields.get_schema.properties[ 'language' ].required = true
@@ -18,6 +18,7 @@ module Hoodoo
18
18
  schema do
19
19
  uuid :id, :required => true
20
20
  datetime :created_at, :required => true
21
+ datetime :updated_at, :required => false
21
22
  text :kind, :required => true
22
23
  text :language
23
24
 
@@ -62,7 +62,7 @@ module Hoodoo
62
62
  # If an explicit type is given, use that. Otherwise, default to Field
63
63
  # if no block is given, or Object is a block is given.
64
64
  #
65
- value_klass = !options[:type].blank? ? type_option_to_class( options.delete( :type ) ) :
65
+ value_klass = !(options[:type].nil? || options[:type] == '') ? type_option_to_class( options.delete( :type ) ) :
66
66
  (block_given? ? Hoodoo::Presenters::Object : Hoodoo::Presenters::Field)
67
67
 
68
68
  # If we're defining specific keys and some of those keys have fields
@@ -132,12 +132,14 @@ module Hoodoo; module Services
132
132
  MAXIMUM_PAYLOAD_SIZE = 1048576 # 1MB Should Be Enough For Anyone
133
133
 
134
134
  # Maximum *logged* payload (inbound data) size.
135
+ # Keep consistent with max payload size so data is not lost from the logs.
135
136
  #
136
- MAXIMUM_LOGGED_PAYLOAD_SIZE = 1024
137
+ MAXIMUM_LOGGED_PAYLOAD_SIZE = MAXIMUM_PAYLOAD_SIZE
137
138
 
138
139
  # Maximum *logged* response (outbound data) size.
140
+ # Keep consistent with max payload size so data is not lost from the logs.
139
141
  #
140
- MAXIMUM_LOGGED_RESPONSE_SIZE = 1024
142
+ MAXIMUM_LOGGED_RESPONSE_SIZE = MAXIMUM_PAYLOAD_SIZE
141
143
 
142
144
  # The default test session; a Hoodoo::Services::Session instance with the
143
145
  # following characteristics:
@@ -12,11 +12,11 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, be sure to re-run
13
13
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
14
14
  #
15
- VERSION = '2.12.2'
15
+ VERSION = '2.12.7'
16
16
 
17
17
  # The Hoodoo gem date. If this changes, be sure to re-run
18
18
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
19
19
  #
20
- DATE = '2019-07-11'
20
+ DATE = '2021-02-12'
21
21
 
22
22
  end
@@ -362,7 +362,8 @@ describe '#schema' do
362
362
  Hoodoo::UUID.generate,
363
363
  Time.now,
364
364
  'en-gb',
365
- Hoodoo::UUID.generate
365
+ Hoodoo::UUID.generate,
366
+ Time.now
366
367
  )
367
368
 
368
369
  expect(Hoodoo::Data::Resources::World.validate(rendered, true).errors).to eq([])
@@ -707,6 +708,7 @@ describe '#schema' do
707
708
  'id' => @uuid,
708
709
  'kind' => 'World',
709
710
  'created_at' => Hoodoo::Utilities.standard_datetime( @time ),
711
+ 'updated_at' => Hoodoo::Utilities.standard_datetime( @time ),
710
712
  'language' => 'en-gb',
711
713
  'errors_id' => @input['errors_id'],
712
714
  'test_tags' => 'foo,bar,baz',
@@ -729,7 +731,9 @@ describe '#schema' do
729
731
  @input,
730
732
  @uuid,
731
733
  @time,
732
- 'en-gb'
734
+ 'en-gb',
735
+ nil,
736
+ @time
733
737
  )
734
738
  ).to( eq( @output ) )
735
739
  end
@@ -744,7 +748,8 @@ describe '#schema' do
744
748
  @uuid,
745
749
  @time,
746
750
  'en-gb',
747
- fingerprint
751
+ fingerprint,
752
+ @time
748
753
  )
749
754
  ).to( eq( @output ) )
750
755
  end
@@ -6,13 +6,15 @@ describe Hoodoo::Presenters::CommonResourceFields do
6
6
 
7
7
  expect(schema.is_internationalised?()).to eq(false)
8
8
 
9
- expect(schema.properties.count).to eq(7)
9
+ expect(schema.properties.count).to eq(8)
10
10
 
11
11
  expect(schema.properties['id']).to be_a(Hoodoo::Presenters::UUID)
12
12
  expect(schema.properties['id'].required).to eq(true)
13
13
  expect(schema.properties['id'].resource).to be_nil
14
14
  expect(schema.properties['created_at']).to be_a(Hoodoo::Presenters::DateTime)
15
15
  expect(schema.properties['created_at'].required).to eq(true)
16
+ expect(schema.properties['updated_at']).to be_a(Hoodoo::Presenters::DateTime)
17
+ expect(schema.properties['updated_at'].required).to eq(false)
16
18
  expect(schema.properties['kind']).to be_a(Hoodoo::Presenters::Text)
17
19
  expect(schema.properties['kind'].required).to eq(true)
18
20
  expect(schema.properties['language']).to be_a(Hoodoo::Presenters::Text)
@@ -160,7 +160,7 @@ describe Hoodoo::Services::Response do
160
160
  expected = JSON.generate({})
161
161
  expect(status).to eq(200)
162
162
  expect(headers).to eq({'Content-Length' => expected.length.to_s})
163
- expect(body.body).to eq([expected])
163
+ expect(body).to eq([expected])
164
164
  end
165
165
 
166
166
  it 'should return header data correctly' do
@@ -172,7 +172,7 @@ describe Hoodoo::Services::Response do
172
172
  expected = JSON.generate({})
173
173
  expect(status).to eq(200)
174
174
  expect(headers).to eq({'X-Foo' => 'baz', 'X-Bar' => 'boo', 'Content-Length' => expected.length.to_s})
175
- expect(body.body).to eq([expected])
175
+ expect(body).to eq([expected])
176
176
  end
177
177
 
178
178
  it 'should return error condition Rack data correctly' do
@@ -187,7 +187,7 @@ describe Hoodoo::Services::Response do
187
187
  expected = JSON.generate(errors_hash)
188
188
  expect(status).to eq(422) # From the first error we stored, not the second
189
189
  expect(headers).to eq({'Content-Length' => expected.length.to_s})
190
- expect(body.body).to eq([expected])
190
+ expect(body).to eq([expected])
191
191
  end
192
192
 
193
193
  it 'should return non-error condition Rack data correctly with a Hash body' do
@@ -199,7 +199,7 @@ describe Hoodoo::Services::Response do
199
199
  expected = JSON.generate(response_hash)
200
200
  expect(status).to eq(200) # From the first error we stored, not the second
201
201
  expect(headers).to eq({'Content-Length' => expected.length.to_s})
202
- expect(body.body).to eq([expected])
202
+ expect(body).to eq([expected])
203
203
  end
204
204
 
205
205
  it 'returns non-error condition Rack data correctly with an Array body' do
@@ -211,7 +211,7 @@ describe Hoodoo::Services::Response do
211
211
  expected = JSON.generate({'_data' => response_array})
212
212
  expect(status).to eq(200) # From the first error we stored, not the second
213
213
  expect(headers).to eq({'Content-Length' => expected.length.to_s})
214
- expect(body.body).to eq([expected])
214
+ expect(body).to eq([expected])
215
215
  end
216
216
 
217
217
  it 'returns non-error condition Rack data correctly with a dataset size' do
@@ -223,7 +223,7 @@ describe Hoodoo::Services::Response do
223
223
  expected = JSON.generate( { '_data' => response_array, '_dataset_size' => response_array.count } )
224
224
  expect( status ).to eq( 200 )
225
225
  expect( headers ).to eq( { 'Content-Length' => expected.length.to_s } )
226
- expect( body.body ).to eq( [ expected ] )
226
+ expect( body ).to eq( [ expected ] )
227
227
  end
228
228
 
229
229
  it 'returns non-error condition Rack data correctly with an estimated dataset size' do
@@ -235,7 +235,7 @@ describe Hoodoo::Services::Response do
235
235
  expected = JSON.generate( { '_data' => response_array, '_estimated_dataset_size' => response_array.count } )
236
236
  expect( status ).to eq( 200 )
237
237
  expect( headers ).to eq( { 'Content-Length' => expected.length.to_s } )
238
- expect( body.body ).to eq( [ expected ] )
238
+ expect( body ).to eq( [ expected ] )
239
239
  end
240
240
 
241
241
  it 'returns non-error condition Rack data correctly with both an accurate and an estimated dataset size' do
@@ -252,7 +252,7 @@ describe Hoodoo::Services::Response do
252
252
 
253
253
  expect( status ).to eq( 200 )
254
254
  expect( headers ).to eq( { 'Content-Length' => expected.length.to_s } )
255
- expect( body.body ).to eq( [ expected ] )
255
+ expect( body ).to eq( [ expected ] )
256
256
  end
257
257
 
258
258
  it 'should allow pre-encoded strings in the body' do
@@ -261,7 +261,7 @@ describe Hoodoo::Services::Response do
261
261
  status, headers, body = @r.for_rack
262
262
 
263
263
  expect(status).to eq(200)
264
- expect(body.body).to eq(['Hello World!'])
264
+ expect(body).to eq(['Hello World!'])
265
265
  end
266
266
 
267
267
  it 'should raise an exception when the body is in an unsupported format' do
@@ -604,7 +604,7 @@ describe Hoodoo::Utilities do
604
604
  end
605
605
 
606
606
  after :each do
607
- @old_tz.blank? ? ENV.delete( 'TZ' ) : ENV[ 'TZ' ] = @old_tz
607
+ (@old_tz.nil? || @old_tz == '') ? ENV.delete( 'TZ' ) : ENV[ 'TZ' ] = @old_tz
608
608
  end
609
609
 
610
610
  it 'accepts a non-UTC Time and renders a UTC date-time' do
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: 2.12.2
4
+ version: 2.12.7
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: 2019-07-11 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -184,28 +184,28 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '5.2'
187
+ version: 5.2.4.3
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '5.2'
194
+ version: 5.2.4.3
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: activesupport
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '5.2'
201
+ version: 5.2.4.3
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '5.2'
208
+ version: 5.2.4.3
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: database_cleaner
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -598,8 +598,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
598
598
  - !ruby/object:Gem::Version
599
599
  version: '0'
600
600
  requirements: []
601
- rubyforge_project:
602
- rubygems_version: 2.7.7
601
+ rubygems_version: 3.2.9
603
602
  signing_key:
604
603
  specification_version: 4
605
604
  summary: Opinionated APIs