lib/apartment.rb in apartment-0.26.1 vs lib/apartment.rb in apartment-1.0.0

- old
+ new

@@ -1,10 +1,11 @@ require 'apartment/railtie' if defined?(Rails) require 'active_support/core_ext/object/blank' require 'forwardable' require 'active_record' require 'apartment/tenant' +require 'apartment/deprecation' module Apartment class << self @@ -14,11 +15,11 @@ WRITER_METHODS = [:tenant_names, :database_schema_file, :excluded_models, :default_schema, :persistent_schemas, :connection_class, :tld_length, :db_migrate_tenants] attr_accessor(*ACCESSOR_METHODS) attr_writer(*WRITER_METHODS) - def_delegators :connection_class, :connection, :establish_connection + def_delegators :connection_class, :connection, :connection_config, :establish_connection # configure apartment with available options def configure yield self if block_given? end @@ -40,12 +41,14 @@ def excluded_models @excluded_models || [] end def default_schema - @default_schema || "public" + @default_schema || "public" # TODO 'public' is postgres specific end + alias :default_tenant :default_schema + alias :default_tenant= :default_schema= def persistent_schemas @persistent_schemas || [] end @@ -67,26 +70,26 @@ def reset (ACCESSOR_METHODS + WRITER_METHODS).each{|method| remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}") } end def database_names - warn "[Deprecation Warning] `database_names` is now deprecated, please use `tenant_names`" + Apartment::Deprecation.warn "[Deprecation Warning] `database_names` is now deprecated, please use `tenant_names`" tenant_names end def database_names=(names) - warn "[Deprecation Warning] `database_names=` is now deprecated, please use `tenant_names=`" + Apartment::Deprecation.warn "[Deprecation Warning] `database_names=` is now deprecated, please use `tenant_names=`" self.tenant_names=(names) end def use_postgres_schemas - warn "[Deprecation Warning] `use_postgresql_schemas` is now deprecated, please use `use_schemas`" + Apartment::Deprecation.warn "[Deprecation Warning] `use_postgresql_schemas` is now deprecated, please use `use_schemas`" use_schemas end def use_postgres_schemas=(to_use_or_not_to_use) - warn "[Deprecation Warning] `use_postgresql_schemas=` is now deprecated, please use `use_schemas=`" + Apartment::Deprecation.warn "[Deprecation Warning] `use_postgresql_schemas=` is now deprecated, please use `use_schemas=`" self.use_schemas = to_use_or_not_to_use end end # Exceptions @@ -96,20 +99,8 @@ AdapterNotFound = Class.new(ApartmentError) # Tenant specified is unknown TenantNotFound = Class.new(ApartmentError) - # Raised when database cannot find the specified database - DatabaseNotFound = Class.new(TenantNotFound) - - # Raised when database cannot find the specified schema - SchemaNotFound = Class.new(TenantNotFound) - # The Tenant attempting to be created already exists TenantExists = Class.new(ApartmentError) - - # Raised when trying to create a database that already exists - DatabaseExists = Class.new(TenantExists) - - # Raised when trying to create a schema that already exists - SchemaExists = Class.new(TenantExists) end