duty_free 1.0.6 → 1.0.7

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
  SHA256:
3
- metadata.gz: f9ac922dd807fc18539ff130c1ccf63412e837acbe4eba0127423235c11d0f1e
4
- data.tar.gz: e5c27fe4a58718dcbbd4c5ebc1aed2dbb5e7e4b386c977e0ec31269cfad08d48
3
+ metadata.gz: b16ccd7258656d274fc6b1f8798c5b5d1f3822570bdd9600f10d55e486a1308d
4
+ data.tar.gz: 9174b6bb8521edfacd9ddde72decc8a5b9274f33049740914cdd5077f9d52c59
5
5
  SHA512:
6
- metadata.gz: 54811a68bd34fd5bb881fa19006a7297a8697a3a1575b7060ba7d82e6fcd6d36f545e1d5cfcfc51c756a5b87880e445c415924d2f54aa39471f0b884f0b4c6c4
7
- data.tar.gz: 32ccb88e429e64bccb59c7741955b99537c661d6416d6f8c352cb384df728081d5b54079cb2dbd904203fbcf1c60abb1a4a7c70bee9c2764fa1622eaaeb6843f
6
+ metadata.gz: 8ba849219eca3426c396be95fc29828c9fe60cd4c538004796d9cc9c17d8be11541c1b18f3d6ed0a89e2980570caafe88dbfc9772ca2d48fe17239c5417d71d8
7
+ data.tar.gz: 54fa0c8b8bd4719863ebeb246f1d1fd21decec7ed1061b9ab8b447e2d38216a52ad427e2a3964564d19a6016ee572b6a95d7f269ed409e90df4c96cbbec01910
@@ -137,7 +137,8 @@ ActiveSupport.on_load(:active_record) do
137
137
  # This aliasing avoids the warning:
138
138
  # "no type cast defined for type "numeric" with oid 1700. Please cast this type
139
139
  # explicitly to TEXT to be safe for future changes."
140
- PG::BasicTypeRegistry.alias_type(0, 'numeric', 'text')
140
+ PG::BasicTypeRegistry.alias_type(0, 'numeric', 'text') # oid 1700
141
+ PG::BasicTypeRegistry.alias_type(0, 'time', 'text') # oid 1083
141
142
  PG::BasicTypeMapForResults.new(klass.connection.raw_connection)
142
143
  end.call
143
144
  rslt.to_a
@@ -244,6 +245,14 @@ ActiveSupport.on_load(:active_record) do
244
245
  PGError = PG::Error
245
246
  end
246
247
 
248
+ unless DateTime.instance_methods.include?(:nsec)
249
+ class DateTime < Date
250
+ def nsec
251
+ (sec_fraction * 1000000000).to_i
252
+ end
253
+ end
254
+ end
255
+
247
256
  include ::DutyFree::Extensions
248
257
  end
249
258
 
@@ -59,6 +59,9 @@ module DutyFree
59
59
 
60
60
  # So we can properly create the SELECT list, create a mapping between our
61
61
  # column alias prefixes and the aliases AREL creates.
62
+ # %%% If with Rails 3.1 and older you get "NoMethodError: undefined method `eq' for nil:NilClass"
63
+ # when trying to call relation.arel, then somewhere along the line while navigating a has_many
64
+ # relationship it can't find the proper foreign key.
62
65
  core = relation.arel.ast.cores.first
63
66
  # Accommodate AR < 3.2
64
67
  arel_alias_names = if core.froms.is_a?(Arel::Table)
@@ -284,7 +287,19 @@ module DutyFree
284
287
  sub_next = klass.new(criteria || {})
285
288
  to_be_saved << [sub_next, sub_obj, bt_name, sub_next]
286
289
  end
290
+ # This wires it up in memory, but doesn't yet put the proper foreign key ID in
291
+ # place when the primary object is a new one (and thus not having yet been saved
292
+ # doesn't yet have an ID).
293
+ # binding.pry if !sub_next.new_record? && sub_next.name == 'Squidget Widget' # !sub_obj.changed?
294
+ # # %%% Question is -- does the above set changed? when a foreign key is not yet set
295
+ # # and only the in-memory object has changed?
296
+ is_yet_changed = sub_obj.changed?
287
297
  sub_obj.send(bt_name, sub_next)
298
+
299
+ # We need this in the case of updating the primary object across a belongs_to when
300
+ # the foreign one already exists and is not otherwise changing, such as when it is
301
+ # not a new one, so wouldn't otherwise be getting saved.
302
+ to_be_saved << [sub_obj] if !sub_obj.new_record? && !is_yet_changed && sub_obj.changed?
288
303
  # From a has_many or has_one?
289
304
  # Rails 4.0 and later can do: sub_next.is_a?(ActiveRecord::Associations::CollectionProxy)
290
305
  elsif [:has_many, :has_one].include?(assoc.macro) && !assoc.options[:through]
@@ -302,9 +317,11 @@ module DutyFree
302
317
  if sub_hm
303
318
  sub_next = sub_hm
304
319
  elsif assoc.macro == :has_one
305
- bt_name = "#{assoc.inverse.name}="
320
+ # assoc.active_record.name.underscore is only there to support older Rails
321
+ # that doesn't do automatic inverse_of
322
+ ho_name = "#{assoc.inverse_of&.name || assoc.active_record.name.underscore}="
306
323
  sub_next = assoc.klass.new(criteria)
307
- to_be_saved << [sub_next, sub_obj, bt_name, sub_next]
324
+ to_be_saved << [sub_next, sub_next, ho_name, sub_obj]
308
325
  else
309
326
  # Two other methods that are possible to check for here are :conditions and
310
327
  # :sanitized_conditions, which do not exist in Rails 4.0 and later.
@@ -360,20 +377,18 @@ module DutyFree
360
377
  row_errors[v.name] << "Boolean value \"#{row[key]}\" in column #{key + 1} not recognized"
361
378
  end
362
379
  end
380
+
381
+ is_yet_changed = sub_obj.changed?
363
382
  sub_obj.send(sym, row[key])
383
+ # If this one is transitioning from having not changed to now having been changed,
384
+ # and is not a new one anyway that would already be lined up to get saved, then we
385
+ # mark it to now be saved.
386
+ to_be_saved << [sub_obj] if !sub_obj.new_record? && !is_yet_changed && sub_obj.changed?
364
387
  # else
365
388
  # puts " #{sub_obj.class.name} doesn't respond to #{sym}"
366
389
  end
390
+ # Try to save final sub-object(s) if any exist
367
391
  ::DutyFree::Extensions._save_pending(to_be_saved)
368
- # Try to save a final sub-object if one exists
369
- # sub_obj.save if sub_obj && this_path && !is_has_one && sub_obj.valid?
370
-
371
- # # Wire up has_one associations
372
- # has_ones.each do |hasone|
373
- # parent = sub_objects[hasone[0..-2].map(&:to_s).join(',')] || obj
374
- # hasone_object = sub_objects[hasone.map(&:to_s).join(',')]
375
- # parent.send("#{hasone[-1]}=", hasone_object) if parent.new_record? || hasone_object.valid?
376
- # end
377
392
 
378
393
  # Reinstate any missing polymorphic _type and _id values
379
394
  polymorphics.each do |poly|
@@ -454,9 +469,13 @@ module DutyFree
454
469
  # Don't let this fool you -- we really are in search of the foreign key name here,
455
470
  # and Rails 3.0 and older used some fairly interesting conventions, calling it instead
456
471
  # the "primary_key_name"!
457
- if assoc.respond_to?(:primary_key_name) && (fk_name = assoc.primary_key_name) &&
458
- col_names.include?(fk_name.to_s)
459
- return fk_name
472
+ if assoc.respond_to?(:primary_key_name)
473
+ if (fk_name = assoc.primary_key_name) && col_names.include?(fk_name.to_s)
474
+ return fk_name
475
+ end
476
+ if (fk_name = assoc.inverse_of.primary_key_name) && col_names.include?(fk_name.to_s)
477
+ return fk_name
478
+ end
460
479
  end
461
480
 
462
481
  puts "* Wow, had no luck at all finding a foreign key for #{assoc.inspect}"
@@ -721,6 +740,11 @@ module DutyFree
721
740
  # can be added properly to those new objects. Finally at the end also called to save everything.
722
741
  def self._save_pending(to_be_saved)
723
742
  while (tbs = to_be_saved.pop)
743
+ # puts "Will be calling #{tbs[1].class.name} #{tbs[1]&.id} .#{tbs[2]} #{tbs[3].class.name} #{tbs[3]&.id}"
744
+
745
+ # Wire this one up if it had came from a has_one association
746
+ tbs[1].send(tbs[2], tbs[3]) if tbs[0] == tbs[1]
747
+
724
748
  ais = (tbs.first.class.respond_to?(:around_import_save) && tbs.first.class.method(:around_import_save)) ||
725
749
  (respond_to?(:around_import_save) && method(:around_import_save))
726
750
  if ais
@@ -735,11 +759,12 @@ module DutyFree
735
759
  else
736
760
  puts "* Unable to save #{tbs.first.inspect}"
737
761
  end
738
- # puts "Save #{tbs.first.class.name} #{tbs.first&.id} #{!tbs.first.new_record?}"
739
- unless tbs[1].nil? || tbs.first.new_record?
740
- # puts "Calling #{tbs[1].class.name} #{tbs[1]&.id} .#{tbs[2]} #{tbs[3].class.name} #{tbs[3]&.id}"
741
- tbs[1].send(tbs[2], tbs[3])
742
- end
762
+
763
+ next if tbs[1].nil? || # From a has_many?
764
+ tbs[0] == tbs[1] || # From a has_one?
765
+ tbs.first.new_record?
766
+
767
+ tbs[1].send(tbs[2], tbs[3])
743
768
  end
744
769
  end
745
770
 
@@ -238,11 +238,11 @@ module DutyFree
238
238
  if klass.columns.map(&:name).include?(attrib)
239
239
  s << attrib
240
240
  else
241
- bt_names = klass.reflect_on_all_associations.each_with_object([]) do |assoc, names|
242
- names << assoc.name.to_s if assoc.is_a?(ActiveRecord::Reflection::BelongsToReflection)
241
+ ho_and_bt_names = klass.reflect_on_all_associations.each_with_object([]) do |assoc, names|
242
+ names << assoc.name.to_s if assoc.belongs_to? || assoc.macro == :has_one
243
243
  names
244
244
  end
245
- unless bt_names.include?(attrib)
245
+ unless ho_and_bt_names.include?(attrib)
246
246
  puts "* In the #{klass.name} model \"validates_presence_of :#{attrib}\" should be removed as it does not refer to any existing column."
247
247
  errored_columns << klass_col
248
248
  end
@@ -5,7 +5,7 @@ module DutyFree
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 6
8
+ TINY = 7
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duty_free
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits