From 61d31e964fef8fae30f166d08b07ec140b619dc3 Mon Sep 17 00:00:00 2001 From: Evgeniy Dolzhenko Date: Wed, 22 Sep 2010 23:01:40 -0700 Subject: [PATCH] Make compatible with Rails 2 and 3 --- lib/silent-postgres.rb | 38 ++++++++++++++++++---------------- lib/silent-postgres/railtie.rb | 20 ++++++++++++++++++ silent-postgres.gemspec | 9 ++++++++ 3 files changed, 49 insertions(+), 18 deletions(-) mode change 100644 => 100755 lib/silent-postgres.rb create mode 100755 lib/silent-postgres/railtie.rb create mode 100755 silent-postgres.gemspec diff --git a/lib/silent-postgres.rb b/lib/silent-postgres.rb old mode 100644 new mode 100755 index 3825edb..b8d38f1 --- a/lib/silent-postgres.rb +++ b/lib/silent-postgres.rb @@ -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 <