Make compatible with Rails 2 and 3
This commit is contained in:
parent
e0015391fb
commit
61d31e964f
10
lib/silent-postgres.rb
Normal file → Executable file
10
lib/silent-postgres.rb
Normal file → Executable file
@ -1,3 +1,7 @@
|
||||
if %w(test development).include?(ENV["RAILS_ENV"])
|
||||
|
||||
require "silent-postgres/railtie"
|
||||
|
||||
module SilentPostgres
|
||||
SILENCED_METHODS = %w(tables indexes column_definitions pk_and_sequence_for last_insert_id)
|
||||
|
||||
@ -8,7 +12,7 @@ module SilentPostgres
|
||||
end
|
||||
|
||||
SILENCED_METHODS.each do |m|
|
||||
eval <<METHOD
|
||||
eval <<-METHOD
|
||||
def #{m}_with_silencer(*args)
|
||||
@logger.silence do
|
||||
#{m}_without_silencer(*args)
|
||||
@ -18,7 +22,5 @@ METHOD
|
||||
end
|
||||
end
|
||||
|
||||
if %w(test development).include?(ENV["RAILS_ENV"])
|
||||
puts "Silencing Postgres"
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, SilentPostgres)
|
||||
end
|
||||
|
||||
|
20
lib/silent-postgres/railtie.rb
Executable file
20
lib/silent-postgres/railtie.rb
Executable file
@ -0,0 +1,20 @@
|
||||
module SilentPostgres
|
||||
def self.init!
|
||||
puts "Silencing Postgres"
|
||||
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, SilentPostgres)
|
||||
end
|
||||
|
||||
if defined?(Rails::Railtie)
|
||||
# Rails 3
|
||||
class Railtie < Rails::Railtie
|
||||
initializer 'silent_postgres.insert_into_active_record' do
|
||||
ActiveSupport.on_load :active_record do
|
||||
SilentPostgres.init!
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
# Rails 2
|
||||
init!
|
||||
end
|
||||
end
|
9
silent-postgres.gemspec
Executable file
9
silent-postgres.gemspec
Executable file
@ -0,0 +1,9 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{silent-postgres}
|
||||
s.version = "0.0.4"
|
||||
s.summary = %q{Rails plugin that silences Postgresql connection adapter verbose output}
|
||||
s.email = ['bragi@ragnarson.com', 'dolzenko@gmail.com']
|
||||
s.homepage = %q{http://github.com/dolzenko/silent-postgres}
|
||||
s.authors = ["Łukasz Piestrzeniewicz", "Evgeniy Dolzhenko"]
|
||||
s.files = ["MIT-LICENSE", "README", "lib", "silent-postgres.gemspec", "lib/silent-postgres", "lib/silent-postgres/railtie.rb", "lib/silent-postgres.rb", "init.rb"]
|
||||
end
|
Loading…
Reference in New Issue
Block a user