Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Properly load railtie and init in Rails 3

  • Loading branch information...
commit 64ba3f9013cc67ddd0494646b97cf0b83042de62 1 parent 826a635
@nesquena authored
View
3  lib/query_reviewer.rb
@@ -49,3 +49,6 @@ def self.enabled?
require "query_reviewer/controller_extensions"
require "query_reviewer/sql_query_collection"
end
+
+# Rails Integration
+require 'query_reviewer/rails' if defined?(Rails)
View
34 lib/query_reviewer/rails.rb
@@ -0,0 +1,34 @@
+require 'query_reviewer'
+require 'rails'
+
+if defined?(Rails::Railtie)
+ module QueryReviewer
+ class Railtie < Rails::Railtie
+ rake_tasks do
+ load File.dirname(__FILE__) + "/tasks.rb"
+ end
+
+ initializer "query_reviewer.initialize" do
+ QueryReviewer.inject_reviewer if QueryReviewer.enabled?
+ end
+ end
+ end
+else # Rails 2
+ QueryReviewer.inject_reviewer
+end
+
+module QueryReviewer
+ def self.inject_reviewer
+ # Load adapters
+ ActiveRecord::Base
+ adapter_class = ActiveRecord::ConnectionAdapters::MysqlAdapter if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
+ adapter_class = ActiveRecord::ConnectionAdapters::Mysql2Adapter if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
+ adapter_class.send(:include, QueryReviewer::MysqlAdapterExtensions)
+ # Load into controllers
+ ActionController::Base.send(:include, QueryReviewer::ControllerExtensions)
+ Array.send(:include, QueryReviewer::ArrayExtensions)
+ if ActionController::Base.respond_to?(:append_view_path)
+ ActionController::Base.append_view_path(File.dirname(__FILE__) + "/lib/query_reviewer/views")
+ end
+ end
+end
View
12 rails/init.rb
@@ -1,13 +1 @@
-# Include hook code here
-
require 'query_reviewer'
-
-if QueryReviewer.enabled?
- ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, QueryReviewer::MysqlAdapterExtensions)
- ActionController::Base.send(:include, QueryReviewer::ControllerExtensions)
- Array.send(:include, QueryReviewer::ArrayExtensions)
-
- if ActionController::Base.respond_to?(:append_view_path)
- ActionController::Base.append_view_path(File.dirname(__FILE__) + "/lib/query_reviewer/views")
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.