acts_as_multi_tenant 2.2.0 → 2.3.0

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: ea202338b794ee4adfc597b052d9f7672b6260810c89ac7b285e6881b2c76295
4
- data.tar.gz: 38b766def8f5e4d62349ebe46a338356118af1a8637e183caa990fffb7f1135d
3
+ metadata.gz: 0f798021b2f0d018f7487922f84044db2b9ef1ea6e961ac134fe7cf602774119
4
+ data.tar.gz: c438ed78359432b8ac602e0c080304b14cf3ed5100e959de379f3d407b6e2a36
5
5
  SHA512:
6
- metadata.gz: e4bb242fdabdbeddfd4d864360f4469903f1e85237ac3bec1ac07cf804f349f3af58b958d0265f5f266258d2636af9161eb6a55e3c7407e751f27a23a1a43f70
7
- data.tar.gz: ab71d51d8ea433ac6a466dc29ec4fcf70fafacb0fc55a4b344e0d93b51a4ac60f2607e89d20bede2b5fe01563cfca1a7a228fb85f9e5f3195743bf45428775fd
6
+ metadata.gz: 3cfb7bac41361b0c3c5840ec510e571f513e6addef721f85f5d3f414cd9ba8c943f8de73f105f27b4ef5e88600af63078fbfebeb9d53486c9cecfb4ea30c8c88
7
+ data.tar.gz: e7406e359b33dd5159ab0f2acfdfab721e1d7dcb5d4717f506cfe77396cd5deb3b6803df7924a45062fc58922197a835ffe8c0c7608c415c465d18a522be362b
@@ -61,8 +61,11 @@ module MultiTenant
61
61
  # Assign this model to the current tenant (if any). If there are multiple current tenants this is a no-op.
62
62
  #
63
63
  def assign_to_current_tenant
64
- if self.class.tenant_class.current_tenants.size == 1
65
- current_tenant_id = self.class.tenant_class.current_tenant.send(self.class.tenant_primary_key)
64
+ code_col = self.class.tenant_class.tenant_identifier
65
+ current = self.class.tenant_class.current_tenants
66
+
67
+ if current.size == 1 or current.map(&code_col).uniq.size == 1
68
+ current_tenant_id = self.class.tenant_class.current_tenants.first.send(self.class.tenant_primary_key)
66
69
  send "#{self.class.tenant_foreign_key}=", current_tenant_id
67
70
  end
68
71
  end
@@ -61,6 +61,7 @@ module MultiTenant
61
61
  self.proxied_tenant_inverse_scope = scope
62
62
 
63
63
  extend MultiTenant::ActsAsTenant::TenantGetters
64
+ extend TenantInterface
64
65
  extend case [ref.macro, ref.inverse_of.macro]
65
66
  when [:has_many, :belongs_to], [:has_one, :belongs_to], [:belongs_to, :has_one]
66
67
  ProxiesToTenantSingularInverseAssociation
@@ -79,6 +80,16 @@ module MultiTenant
79
80
  respond_to? :proxied_tenant_class
80
81
  end
81
82
 
83
+ #
84
+ # Class methods to give this the same interface as a "real" tenant class.
85
+ #
86
+ module TenantInterface
87
+ # Returns the tenant_identifier from the proxied class
88
+ def tenant_identifier
89
+ self.proxied_tenant_class.tenant_identifier
90
+ end
91
+ end
92
+
82
93
  #
83
94
  # Class methods for tenant proxies that have a singular inverse association (i.e. belongs_to or has_one).
84
95
  #
@@ -1,4 +1,4 @@
1
1
  module MultiTenant
2
2
  # Gem version
3
- VERSION = '2.2.0'.freeze
3
+ VERSION = '2.3.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_multi_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger