lib/secondbase.rb in secondbase-0.6.0 vs lib/secondbase.rb in secondbase-1.0.0

- old
+ new

@@ -1,46 +2 @@ -require 'active_record' -require 'secondbase/active_record/patches' - -module SecondBase - CONNECTION_PREFIX = 'secondbase' - - require 'secondbase/railtie' - require 'secondbase/rake_method_chain' - - def self.do - "You have just gotten to SecondBase, my friend." - end - - def self.has_runner(env) - ActiveRecord::Base.establish_connection(SecondBase::config(env)) - reset_visitor_cache - end - - def self.config(env) - ActiveRecord::Base.configurations[SecondBase::CONNECTION_PREFIX][env] - end - - # TODO: We should really look at faking out the connection used by ActiveRecord - # during migrations, this would prevent us from digging around Arel internals. - # Arel caches the SQL translator based on the engine (ActiveRecord::Base). This - # means that if we swap out the base connection we risk the SQL translator being wrong. - # This is an ugly hack that resets the adapter. See Line 27 of Arel's visitors.rb class. - def self.reset_visitor_cache - if Rails.version.to_i >= 3 - engine = ActiveRecord::Base - adapter = engine.connection_pool.spec.config[:adapter] - Arel::Visitors::ENGINE_VISITORS[engine] = (Arel::Visitors::VISITORS[adapter] || Arel::Visitors::ToSql).new(engine) - end - end -end - -module FirstBase - def self.config(env) - ActiveRecord::Base.configurations[env] - end - - def self.has_runner(env) - ActiveRecord::Base.establish_connection(FirstBase::config(env)) - SecondBase.reset_visitor_cache - end -end \ No newline at end of file +require 'second_base'