Skip to content
Browse files

using active_support delegate instead of custom baked delegation in d…

…atabase
  • Loading branch information...
1 parent 014c279 commit 8d993ba94ca48c31962e0b09c054c75529d3d785 @bradrobertson bradrobertson committed Jun 23, 2011
Showing with 4 additions and 11 deletions.
  1. +4 −11 lib/apartment/database.rb
View
15 lib/apartment/database.rb
@@ -1,26 +1,19 @@
-require 'active_support/core_ext/string/inflections' # for `constantize`
+require 'active_support/core_ext/module/delegation'
module Apartment
module Database
- MULTI_TENANT_METHODS = [:create, :switch, :reset, :connect_and_reset, :process, :seed]
-
class << self
+ # pass these methods to our adapter
+ delegate :create, :switch, :reset, :connect_and_reset, :process, :seed, :to => :adapter
+
# Call init to establish a connection to the public schema on all excluded models
# This must be done before creating any new schemas or switching
def init
connect_exclusions
end
- MULTI_TENANT_METHODS.each do |method|
- class_eval <<-RUBY
- def #{method}(*args, &block)
- adapter.send(:#{method}, *args, &block)
- end
- RUBY
- end
-
def adapter
@adapter ||= begin
adapter_method = "#{config[:adapter]}_adapter"

0 comments on commit 8d993ba

Please sign in to comment.
Something went wrong with that request. Please try again.