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 <