lib/slavery.rb in slavery-1.1.0 vs lib/slavery.rb in slavery-1.1.1

- old
+ new

@@ -81,12 +81,15 @@ # Create an anonymous AR class to hold slave connection def slave_connection_holder @slave_connection_holder ||= Class.new(ActiveRecord::Base) { self.abstract_class = true - establish_connection("#{Slavery.env}_slave") + + spec = ["#{Slavery.env}_slave", Slavery.env].find do |spec| + ActiveRecord::Base.configurations[spec] + end or raise Error.new("#{Slavery.env}_slave or #{Slavery.env} must exist!") + + establish_connection spec } - rescue ActiveRecord::AdapterNotSpecified - raise Error.new("#{Slavery.env}_slave does not exist!") end end end