exwiw 0.8.0 → 0.8.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: c9644b63d339ba01e55e57dd12274ea89af28eef67fda6bdb1201202d52e0f61
4
- data.tar.gz: 40ce93cb0342d35d684119fb8f0c520f05b46fbcb8f486ceed2f1c8b9c8c354c
3
+ metadata.gz: 80610cc2d13a87793171563b2b8e4ff0568135eb987b550dd9f89bffe89b1d67
4
+ data.tar.gz: 5e9f4976043571647163e9f743c3c8fb709a29944b590c55424dce374cca3269
5
5
  SHA512:
6
- metadata.gz: c5cb48eb2c6757768621aaab607cf9bbe90de06f169b672be9f188a12d21f104a6c34e77c101bd0b06b50c4448422906772c56c205bb9f30e4dce14baafb664c
7
- data.tar.gz: 45ec7c49d36c2316238d42ff13055d0183f11151579e20d7f15c4eab05ed40a34d2d3144737d1eaa38c4e2cc2c2abecf45c9eb77276f38c5a4aa38355f5ed68b
6
+ metadata.gz: 8508aaa2d9cba3310a9ee4d4b940682b894bbafcab9672e4ccca5fb8f1a4b43e6fe9c36cbfcd0efe8f12c5308fa9be33aeb16d53b6d98ef71692ec2e30076be0
7
+ data.tar.gz: 8a1a8187e7547f4ce0eeaee458d36b16e56c08c1f2275977127de56a49eb2a3b25e22d8c52d3678fa6ea91e553ebf6c69bf943e5bb108e3984fa8fc34f03a2f0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.8.1] - 2026-06-24
6
+
7
+ ### Fixed
8
+
9
+ - **`schema:generate` skips a `belongs_to` whose target is not an ActiveRecord model instead of crashing.** A `belongs_to` can point at a non-ActiveRecord class — most commonly an ActiveHash/ActiveYaml master (`belongs_to :equipment, class_name: "SomeActiveYamlModel"`). active_hash registers these as ordinary `belongs_to` reflections, but the target class has no database table, so resolving its `table_name` raised and aborted generation. Such a relation is not a DB edge exwiw can join or extract across, so it is now dropped from the generated belongs_tos; the underlying foreign-key column is still emitted as a plain column. A bare `belongs_to` to a plain non-AR class — which makes ActiveRecord raise while resolving the target — is treated the same way. Polymorphic associations are unaffected.
10
+
5
11
  ## [0.8.0] - 2026-06-24
6
12
 
7
13
  ### Added
@@ -291,7 +291,9 @@ module Exwiw
291
291
  end
292
292
 
293
293
  private def aggregate_belongs_tos(models)
294
- belongs_to_assocs = models.flat_map { |m| belongs_to_associations_for(m) }
294
+ belongs_to_assocs = models
295
+ .flat_map { |m| belongs_to_associations_for(m) }
296
+ .select { |assoc| assoc.polymorphic? || active_record_target?(assoc) }
295
297
  owner_db = database_name_for(models.first)
296
298
 
297
299
  non_polymorphic = belongs_to_assocs
@@ -376,6 +378,31 @@ module Exwiw
376
378
  assocs.reject { |assoc| assoc.equal?(left) }
377
379
  end
378
380
 
381
+ # Whether a (non-polymorphic) belongs_to points at an ActiveRecord model.
382
+ #
383
+ # A belongs_to can target a non-ActiveRecord class — most commonly an
384
+ # ActiveHash/ActiveYaml master (`belongs_to :equipment, class_name:
385
+ # "SomeActiveYamlModel"`). active_hash registers these as ordinary
386
+ # `belongs_to` reflections, yet the target class has no database table, so
387
+ # `assoc.table_name` (which delegates to `klass.table_name`) raises. Such a
388
+ # relation is not a DB edge exwiw can join or extract across, so it is
389
+ # dropped from the generated belongs_tos; the underlying foreign-key column
390
+ # is still emitted as a plain column. Polymorphic associations cannot be
391
+ # `klass`-resolved, so callers must screen those out before calling this.
392
+ #
393
+ # Resolving the target class behaves differently per non-AR shape: an
394
+ # ActiveHash reflection returns the class fine (the crash is later, at
395
+ # `table_name`), while a bare `belongs_to` to a plain class makes AR raise
396
+ # ArgumentError ("... is not an ActiveRecord::Base subclass") right here when
397
+ # the klass is computed. Both mean "not a DB relation", so rescue the lookup
398
+ # and treat either as a non-AR target to skip.
399
+ private def active_record_target?(assoc)
400
+ klass = assoc.klass
401
+ klass.is_a?(Class) && klass < ActiveRecord::Base ? true : false
402
+ rescue StandardError
403
+ false
404
+ end
405
+
379
406
  # Enumerate the concrete models that can be targets of the polymorphic
380
407
  # association `association_name`, by looking them up from every model's
381
408
  # `has_many` / `has_one` `as:` option. The order of `concrete_models` depends
data/lib/exwiw/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Exwiw
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exwiw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia