silent-postgres/lib/silent-postgres.rb

37 lines
828 B
Ruby
Raw Permalink Normal View History

if Rails.env.development? || Rails.env.test?
2010-09-23 06:01:40 +00:00
require "silent-postgres/railtie"
module SilentPostgres
2011-01-15 15:57:25 +00:00
SILENCED_METHODS = %w(tables table_exists? indexes column_definitions pk_and_sequence_for last_insert_id)
2010-09-23 06:01:40 +00:00
def self.included(base)
SILENCED_METHODS.each do |m|
base.send :alias_method_chain, m, :silencer
end
end
2010-09-23 06:01:40 +00:00
SILENCED_METHODS.each do |m|
2011-01-15 15:57:25 +00:00
m1, m2 = if m =~ /^(.*)\?$/
[$1, '?']
else
[m, nil]
end
2010-09-23 06:01:40 +00:00
eval <<-METHOD
2011-01-15 15:57:25 +00:00
def #{m1}_with_silencer#{m2}(*args)
2011-05-25 15:08:24 +00:00
if @logger.respond_to?(:silence)
@logger.silence do
#{m1}_without_silencer#{m2}(*args)
end
else
2011-01-15 15:57:25 +00:00
#{m1}_without_silencer#{m2}(*args)
2010-09-23 06:01:40 +00:00
end
end
2010-09-23 06:01:40 +00:00
METHOD
end
end
2010-09-03 11:40:07 +00:00
end
2010-09-23 06:01:40 +00:00