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 +4 -4
- data/lib/acts_as_tenant/model_extensions.rb +10 -7
- data/lib/acts_as_tenant/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5cec7594cd90ce23b4f75e7ca55064b0b57635798b9134e5d77f3ca006436fe4
|
|
4
|
+
data.tar.gz: 87a74e61e8a0dffe81d83a3df8b1792a45cc931aed5c25f1ac4172e0a47f1716
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
70
|
-
#
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
|
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
|