iron_trail 0.3.0 → 0.3.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
  SHA256:
3
- metadata.gz: d1045d147f220c04f680a9a0553a15b98240dc5bb633780d757596f965eb1093
4
- data.tar.gz: e51d73e5b60ce2a9749e9ccea15eb94fff5dd1632e803a69d7d46059a28c68c7
3
+ metadata.gz: 8707ef34f907444740407aa6074416c88f975a83b2669a5f4b2224f179982225
4
+ data.tar.gz: e4a49bc6a32ee02dcb082a78dd96200eaad8b2fc158282afc89aa73ecbdd36c9
5
5
  SHA512:
6
- metadata.gz: 0eccdb0485b087bdf95d3f6d3fe88665278a3e86fa729581b88c877e897114c795dbc2691966083284f9e9eccfde2f4913a1cbd17d3e649a987b30c68ac16b07
7
- data.tar.gz: 33646e1d8a025ddde285d09bf425bbd17037d9504747fff22e8b0a5fdb87ca77ce48399f8b65db7e43a83afcc3be6eeee49509b4b827e55fc89459c54a8685e9
6
+ metadata.gz: 9b14abc242a63677c2a50753db3010ec02ebe3d4dd0cfe1a2e6b3d34195094825f4dd5780dae86e93e9a6803501c4adc89cd5fdfd5d24933183d945d1b538295
7
+ data.tar.gz: 3a2b0d55f7db91e6d961c036ceb037716098226caa9d55dff5c20287a14920f538f99b5f23756dea49435256bfc680e4fbc191f1f2682a88d87716b0406ef72c
@@ -8,8 +8,8 @@ module IronTrail
8
8
  def update_operation? = (operation == 'u')
9
9
  def delete_operation? = (operation == 'd')
10
10
 
11
- def reify
12
- Reifier.reify(self)
11
+ def reify(**)
12
+ Reifier.reify(self, **)
13
13
  end
14
14
 
15
15
  # We don't store the class name of the object, but we do store the rec_table.
@@ -2,11 +2,22 @@
2
2
 
3
3
  module IronTrail
4
4
  module Reifier
5
- def self.reify(trail)
5
+ NOT_GIVEN = Object.new.freeze
6
+ private_constant :NOT_GIVEN
7
+
8
+ # Pass `record:` when the current row is already loaded, e.g. when reifying many trails at
9
+ # once, to skip the per-trail lookup. Pass `nil` when the row no longer exists. The record
10
+ # is mutated in place, so pass one no other code is holding on to.
11
+ def self.reify(trail, record: NOT_GIVEN)
6
12
  source_attributes = (trail.delete_operation? ? trail.rec_old : trail.rec_new)
7
13
  klass = model_from_table_name(trail.rec_table, source_attributes['type'])
8
14
 
9
- record = klass.where(id: trail.rec_id).first || klass.new
15
+ if record.equal?(NOT_GIVEN)
16
+ record = klass.where(id: trail.rec_id).first
17
+ elsif record && !record.instance_of?(klass)
18
+ raise ArgumentError, "expected a #{klass.name}, got a #{record.class.name}"
19
+ end
20
+ record ||= klass.new
10
21
 
11
22
  source_attributes.each do |name, value|
12
23
  if record.has_attribute?(name)
@@ -1,5 +1,5 @@
1
1
  # frozen_literal_string: true
2
2
 
3
3
  module IronTrail
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Diego Piske
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  requirements: []
169
- rubygems_version: 4.0.16
169
+ rubygems_version: 4.0.20
170
170
  specification_version: 4
171
171
  summary: Creates a trail strong as iron
172
172
  test_files: []