Module: Roomer::Utils
- Included in:
- Roomer
- Defined in:
- lib/roomer/utils.rb
Instance Method Summary collapse
-
#current_tenant ⇒ Symbol
Fetches the current tenant.
-
#current_tenant=(val) ⇒ Symbol
Sets current tenant from ApplicationController into a Thread local variable.
-
#ensure_tenant_model_reset ⇒ Object
Reset cached data in tenanted models.
-
#full_shared_schema_migration_path ⇒ String
Constructs the full path to the shared schema directory Example: /Users/Greg/Projects/roomer/db/migrate/global.
-
#full_tenants_table_name ⇒ String
Consutructs the full name for the tenants table with schema Example: ‘global.tenant’.
-
#migrations_directory ⇒ String
Rails DB Migrations Directory.
-
#model_directory ⇒ String
Directory where the models are stored.
-
#reset_current_tenant ⇒ Nil
Reset current tenant.
-
#tenant_model ⇒ Object
Returns tenant model as a constant Example: Tenant.
Instance Method Details
#current_tenant ⇒ Symbol
Fetches the current tenant
52 53 54 55 |
# File 'lib/roomer/utils.rb', line 52 def current_tenant key = :"roomer_current_tenant" Thread.current[key] end |
#current_tenant=(val) ⇒ Symbol
Sets current tenant from ApplicationController into a Thread local variable. Works only with thread-safe Rails as long as it gets set on every request
41 42 43 44 45 46 47 48 |
# File 'lib/roomer/utils.rb', line 41 def current_tenant=(val) key = :"roomer_current_tenant" unless Thread.current[key].try(:url_identifier) == val.url_identifier Thread.current[key] = val ensure_tenant_model_reset end Thread.current[key] end |
#ensure_tenant_model_reset ⇒ Object
Reset cached data in tenanted models
65 66 67 |
# File 'lib/roomer/utils.rb', line 65 def ensure_tenant_model_reset reset_models end |
#full_shared_schema_migration_path ⇒ String
Constructs the full path to the shared schema directory Example: /Users/Greg/Projects/roomer/db/migrate/global
26 27 28 |
# File 'lib/roomer/utils.rb', line 26 def full_shared_schema_migration_path "#{Rails.root}/#{shared_migrations_directory}" end |
#full_tenants_table_name ⇒ String
Consutructs the full name for the tenants table with schema Example: ‘global.tenant’
19 20 21 |
# File 'lib/roomer/utils.rb', line 19 def full_tenants_table_name "#{shared_schema_name}#{schema_seperator}#{tenants_table}" end |
#migrations_directory ⇒ String
Rails DB Migrations Directory
6 7 8 |
# File 'lib/roomer/utils.rb', line 6 def migrations_directory ActiveRecord::Migrator.migrations_path end |
#model_directory ⇒ String
Directory where the models are stored
12 13 14 |
# File 'lib/roomer/utils.rb', line 12 def model_directory File.join("app","models") end |
#reset_current_tenant ⇒ Nil
Reset current tenant
59 60 61 62 |
# File 'lib/roomer/utils.rb', line 59 def reset_current_tenant key = :"roomer_current_tenant" Thread.current[key] = nil end |
#tenant_model ⇒ Object
Returns tenant model as a constant Example: Tenant
33 34 35 |
# File 'lib/roomer/utils.rb', line 33 def tenant_model Roomer.tenants_table.to_s.classify.constantize end |