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