Class: PG::Connection
- Inherits:
-
Object
- Object
- PG::Connection
- Defined in:
- lib/pg_faker.rb
Class Attribute Summary collapse
-
.fake_delay_seconds ⇒ Object
Returns the value of attribute fake_delay_seconds.
-
.fake_delays ⇒ Object
Returns the value of attribute fake_delays.
-
.fake_errors ⇒ Object
Returns the value of attribute fake_errors.
-
.fake_strategy ⇒ Object
Returns the value of attribute fake_strategy.
Class Method Summary collapse
- .alter_methods(*ms) ⇒ Object (also: alter_method)
- .start_intermittent_delay_and_error ⇒ Object
- .stop_intermittent_delay_and_error ⇒ Object
- .unalter_methods(*ms) ⇒ Object (also: unalter_method)
Class Attribute Details
.fake_delay_seconds ⇒ Object
Returns the value of attribute fake_delay_seconds.
6 7 8 |
# File 'lib/pg_faker.rb', line 6 def fake_delay_seconds @fake_delay_seconds end |
.fake_delays ⇒ Object
Returns the value of attribute fake_delays.
6 7 8 |
# File 'lib/pg_faker.rb', line 6 def fake_delays @fake_delays end |
.fake_errors ⇒ Object
Returns the value of attribute fake_errors.
6 7 8 |
# File 'lib/pg_faker.rb', line 6 def fake_errors @fake_errors end |
.fake_strategy ⇒ Object
Returns the value of attribute fake_strategy.
6 7 8 |
# File 'lib/pg_faker.rb', line 6 def fake_strategy @fake_strategy end |
Class Method Details
.alter_methods(*ms) ⇒ Object Also known as: alter_method
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 |
.start_intermittent_delay_and_error ⇒ Object
8 9 10 |
# 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 ⇒ Object
12 13 14 |
# File 'lib/pg_faker.rb', line 12 def stop_intermittent_delay_and_error @fake_strategy = nil end |
.unalter_methods(*ms) ⇒ Object Also known as: unalter_method
34 35 36 37 38 39 40 41 42 43 |
# 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 |