composable-tenant 0.0.6 → 0.0.7

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: 876aa27d3aa66bac41721e6df1882f55b984939a260763ec9851aad8e70d1773
4
- data.tar.gz: 69de9074be96fe457a016af2a92447e647c9e505148e51e8f3057a1e9460c73f
3
+ metadata.gz: 9ac28d848a33cbdf2b98f377b61a1aba16c36b628899a7db9f70bf763614fe83
4
+ data.tar.gz: 0e50ddb91145765338c8caad529b01d1d6eb384dafd923060597ef5f85c6b8c3
5
5
  SHA512:
6
- metadata.gz: 595f21923606b423a418c630796cabb746c8e2377666526a2ab05d281e25a2f04b79061b7b9aed7a36538ac2e63b88a609f4554aca9abbc95bcb96ad2bedbdd4
7
- data.tar.gz: 792f4378c8d3cef43a6c896260ead1cb842bd797627dbde4b446ea67c922147f9fe78f9fde0b4ca947c92a1d50c57dd57fc28977015264b416ebad325f779d9d
6
+ metadata.gz: 12dfe27c94919769ac59a492dfdcdb3ff00eb4e7c29283956ca24b7ae68e05833f30dacb9e46d44617dc73f350d159c3e0049fef76ac90256bcbb20b58b4bf68
7
+ data.tar.gz: 40969548de1a1edb3cdd81a29f7b5a1240d92e7fa35e69a972686edf3d68ba80a2f38af3445e02f185688d1c01817380b24cc665694c395f5befb0b27b0aa40c
@@ -3,9 +3,25 @@ module Composable
3
3
  class DataSet < ActiveSupport::CurrentAttributes
4
4
  attribute :excluded_tenants
5
5
 
6
+ resets { tenants.clear }
7
+
6
8
  def excluded_tenants
7
9
  super || Set.new
8
10
  end
11
+
12
+ def tenant=(array)
13
+ tenants[array.first.to_sym] = array.last
14
+ end
15
+
16
+ def tenant(tenant)
17
+ tenants[tenant.to_sym]
18
+ end
19
+
20
+ private
21
+
22
+ def tenants
23
+ @tenants ||= {}
24
+ end
9
25
  end
10
26
  end
11
27
  end
@@ -10,7 +10,7 @@ module Composable
10
10
  module VERSION
11
11
  MAJOR = 0
12
12
  MINOR = 0
13
- TINY = 6
13
+ TINY = 7
14
14
  PRE = nil
15
15
 
16
16
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -1,16 +1,21 @@
1
1
  module Composable
2
2
  module Tenant
3
+ def self.without_tenant(*tenants)
4
+ old_excluded_tenants = Composable::Tenant::DataSet.excluded_tenants
5
+ Composable::Tenant::DataSet.excluded_tenants = Set.new(tenants.map(&:to_sym))
6
+ yield
7
+ ensure
8
+ Composable::Tenant::DataSet.excluded_tenants = old_excluded_tenants
9
+ end
10
+
11
+ def self.set_tenant(tenant, record)
12
+ Composable::Tenant::DataSet.tenant = [tenant, record]
13
+ record
14
+ end
15
+
3
16
  module ModelExtensions
4
17
  extend ActiveSupport::Concern
5
18
 
6
- def self.without_tenant(*tenants)
7
- old_excluded_tenants = Composable::Tenant::DataSet.excluded_tenants
8
- Composable::Tenant::DataSet.excluded_tenants = Set.new(tenants.map(&:to_sym))
9
- yield
10
- ensure
11
- Composable::Tenant::DataSet.excluded_tenants = old_excluded_tenants
12
- end
13
-
14
19
  module ClassMethods
15
20
  def tenant(tenant, scope = nil, **options)
16
21
  # Create the association
@@ -21,16 +26,16 @@ module Composable
21
26
 
22
27
  default_scope lambda {
23
28
  return if Composable::Tenant::DataSet.excluded_tenants.include?(tenant.to_sym)
24
- raise Composable::Tenant::NoTenantSet.new(tenant: tenant) unless Current.send(tenant)
29
+ raise Composable::Tenant::NoTenantSet.new(tenant: tenant) unless Composable::Tenant::DataSet.tenant(tenant)
25
30
 
26
- where(foreign_key => Current.send(tenant).send(primary_key))
31
+ where(foreign_key => Composable::Tenant::DataSet.tenant(tenant).send(primary_key))
27
32
  }, all_queries: true
28
33
 
29
34
  # Makes sure new instances have tenant set
30
35
  before_validation lambda { |record|
31
36
  return if Composable::Tenant::DataSet.excluded_tenants.include?(tenant.to_sym)
32
37
 
33
- record.send("#{foreign_key}=", Current.send(tenant).send(primary_key))
38
+ record.send("#{foreign_key}=", Composable::Tenant::DataSet.tenant(tenant).send(primary_key))
34
39
  }, on: :create
35
40
 
36
41
  # Rewrite the accessors to make tenant immutable
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composable-tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jairo Vazquez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-15 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord