acts_as_tenant 2.3.1 → 2.3.2

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: 53bee4c397c092c403da3a466d408aa2df9c7dca123dee7b77c479b99c562f18
4
- data.tar.gz: 0371d342b53123379832d0a612dbd4e957ff2b7af967b658de9911e852659587
3
+ metadata.gz: 5cec7594cd90ce23b4f75e7ca55064b0b57635798b9134e5d77f3ca006436fe4
4
+ data.tar.gz: 87a74e61e8a0dffe81d83a3df8b1792a45cc931aed5c25f1ac4172e0a47f1716
5
5
  SHA512:
6
- metadata.gz: dd9d0883f7a764f9b6c6b917b5b1a1fef68b847ed0afe19389ae776eed8fa5ba3ee26df9a6d0e31df7d08e0b81dd75311d2ab92e43c4a08333856a15ec0e0ce6
7
- data.tar.gz: c92740f25cb15fd95a4adb313dd2e8be5708375dd40159d9421ff0660184f6808bb5173b80d05fbe4211d6aafebbf5999c26700e984567467df3c08bc4b50ad0
6
+ metadata.gz: 9113790a85d64c894287c66e49719a11f764c6e5e9c9c41528654956aa20cd5df3d5cfc02b8483c1c14635d2c48741d785342ed5bc8ed8d7cd700f2db2b2a977
7
+ data.tar.gz: 6d6ac7c894bc2fac0a077d7384c52c03a6ef6911b00f8a2520bd665ab1d523ffc4e8ab83a6f2f572aa33174635ed47b4684d4109d44fd5d3a0a621c35f87bf8d
@@ -66,11 +66,15 @@ module ActsAsTenant
66
66
  end
67
67
  }, on: :create
68
68
 
69
- # Returns the model class named by a polymorphic type column, or nil when the name
70
- # is not a model, such as "Kernel" or "String" submitted in form params
71
- polymorphic_class = lambda do |name|
72
- klass = name&.safe_constantize
69
+ # Returns the model class for a polymorphic association, resolved like Active Record
70
+ # does when loading it so custom type names and integer types work. Returns nil when
71
+ # the type is not a model, such as "Kernel" or "String" submitted in form params.
72
+ polymorphic_class = lambda do |model, reflection|
73
+ klass = model.association(reflection.name).klass
73
74
  klass if klass.is_a?(Class) && klass < ActiveRecord::Base
75
+ rescue NoMethodError # a NameError, but from app code such as polymorphic_class_for
76
+ raise
77
+ rescue NameError
74
78
  end
75
79
 
76
80
  # Returns [tenant id, tenant class] for a record, or nil if it has no tenant.
@@ -81,8 +85,7 @@ module ActsAsTenant
81
85
 
82
86
  if id
83
87
  type = if reflection.polymorphic?
84
- stored_type = model.read_attribute(reflection.foreign_type)
85
- polymorphic_class.call(stored_type)&.polymorphic_name || stored_type
88
+ polymorphic_class.call(model, reflection)&.polymorphic_name || model.read_attribute(reflection.foreign_type)
86
89
  else
87
90
  reflection.klass.polymorphic_name
88
91
  end
@@ -150,7 +153,7 @@ module ActsAsTenant
150
153
  next unless record.validate_tenant_association?(association)
151
154
 
152
155
  klass = if association.polymorphic?
153
- polymorphic_class.call(record.read_attribute(association.foreign_type))
156
+ polymorphic_class.call(record, association)
154
157
  else
155
158
  # Raises for composite keys whose column counts don't match, like loading the association would
156
159
  association.check_validity! if attrs.size > 1
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "2.3.1"
2
+ VERSION = "2.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Matthijssen