class PG::Connection

Attributes

fake_delay_seconds[RW]
fake_delays[RW]
fake_errors[RW]
fake_strategy[RW]

Public Class Methods

alter_method(*ms)
Alias for: alter_methods
alter_methods(*ms) click to toggle source
# File lib/pg_faker.rb, line 16
      def alter_methods(*ms)
        PG::Connection.class_eval do
          ((ms if ms.size > 0) || instance_methods(false)).each do |m|
            alias_method "orig_#{m}".to_sym, m
            eval <<-eos            
              def #{m}(*args)
                PG::Connection.fake_strategy.call(#{m.to_sym.inspect}, *args) if PG::Connection.fake_strategy.is_a?(Proc)
                sleep(PG::Connection.fake_delay_seconds) if PG::Connection.fake_delays
                puts "intercepted: PG::Connection.#{m} \#{args.inspect}"
                raise PG::Error.new("fake error raised by pg_faker") if PG::Connection.fake_errors
                orig_#{m} *args          
              end
            eos
          end
        end
      end
Also aliased as: alter_method
start_intermittent_delay_and_error() click to toggle source
# File lib/pg_faker.rb, line 8
def start_intermittent_delay_and_error
  @fake_strategy = lambda {|m, *args| PG::Connection.fake_delays = [true, false].sample; PG::Connection.fake_errors = [true, false].sample; puts "#{m}(#{args.inspect}) fake_delays=#{PG::Connection.fake_delays} fake_errors=#{PG::Connection.fake_errors}" }
end
stop_intermittent_delay_and_error() click to toggle source
# File lib/pg_faker.rb, line 12
def stop_intermittent_delay_and_error
  @fake_strategy = nil
end
unalter_method(*ms)
Alias for: unalter_methods
unalter_methods(*ms) click to toggle source
# File lib/pg_faker.rb, line 34
def unalter_methods(*ms)
  PG::Connection.class_eval do
    meths = instance_methods(false)
    ((ms if ms.size > 0) || meths).each do |m|
      orig_m = "orig_#{m}".to_sym
      alias_method m, orig_m if meths.include?(orig_m)
      remove_method orig_m
    end
  end
end
Also aliased as: unalter_method