Make compatible with Rails 2 and 3
This commit is contained in:
parent
e0015391fb
commit
61d31e964f
16
lib/silent-postgres.rb
Normal file → Executable file
16
lib/silent-postgres.rb
Normal file → Executable file
@ -1,4 +1,8 @@
|
|||||||
module SilentPostgres
|
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)
|
SILENCED_METHODS = %w(tables indexes column_definitions pk_and_sequence_for last_insert_id)
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
@ -8,17 +12,15 @@ module SilentPostgres
|
|||||||
end
|
end
|
||||||
|
|
||||||
SILENCED_METHODS.each do |m|
|
SILENCED_METHODS.each do |m|
|
||||||
eval <<METHOD
|
eval <<-METHOD
|
||||||
def #{m}_with_silencer(*args)
|
def #{m}_with_silencer(*args)
|
||||||
@logger.silence do
|
@logger.silence do
|
||||||
#{m}_without_silencer(*args)
|
#{m}_without_silencer(*args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
METHOD
|
METHOD
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
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