Module: Tenantable::Schema::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/tenantable/schema/model.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#current_schema ⇒ Object
13 14 15 |
# File 'lib/tenantable/schema/model.rb', line 13 def current_schema raise "Tenantable::Schema#current_schema must be override in the model" end |
#generate_schema_UUID ⇒ Object
17 18 19 20 21 |
# File 'lib/tenantable/schema/model.rb', line 17 def generate_schema_UUID alphabet = ('a'..'z').to_a first_letter = alphabet[ rand alphabet.size ] [first_letter, Time.new.to_time.to_i.to_s, SecureRandom.hex(10).to_s].flatten.join("") end |
#schema_bounded ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/tenantable/schema/model.rb', line 5 def schema_bounded Database::Adapter.vendor.create_schema(current_schema) unless Database::Adapter.vendor.schemas.include? current_schema ActiveRecord::Base.connection.schema_search_path = current_schema yield ensure ActiveRecord::Base.connection.schema_search_path = Database::Adapter.vendor.public_schema end |