lib/apartment.rb in apartment-0.19.0 vs lib/apartment.rb in apartment-0.20.0

- old
+ new

@@ -1,19 +1,22 @@ require 'apartment/railtie' if defined?(Rails) -require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/blank' +require 'forwardable' module Apartment class << self + + extend Forwardable + ACCESSOR_METHODS = [:use_schemas, :seed_after_create, :prepend_environment, :append_environment] - WRITER_METHODS = [:database_names, :excluded_models, :default_schema, :persistent_schemas, :connection_class] + WRITER_METHODS = [:database_names, :database_schema_file, :excluded_models, :default_schema, :persistent_schemas, :connection_class] attr_accessor(*ACCESSOR_METHODS) attr_writer(*WRITER_METHODS) - delegate :connection, :establish_connection, to: :connection_class + def_delegators :connection_class, :connection, :establish_connection # configure apartment with available options def configure yield self if block_given? end @@ -38,12 +41,18 @@ def connection_class @connection_class || ActiveRecord::Base end + def database_schema_file + return @database_schema_file if defined?(@database_schema_file) + + @database_schema_file = Rails.root.join('db', 'schema.rb') + end + # Reset all the config for Apartment def reset - (ACCESSOR_METHODS + WRITER_METHODS).each{|method| instance_variable_set(:"@#{method}", nil) } + (ACCESSOR_METHODS + WRITER_METHODS).each{|method| remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}") } end def use_postgres_schemas warn "[Deprecation Warning] `use_postgresql_schemas` is now deprecated, please use `use_schemas`" use_schemas