Class: Greenjaguar::PolicyBuilder
- Inherits:
-
Object
- Object
- Greenjaguar::PolicyBuilder
- Defined in:
- lib/greenjaguar/policy_builder.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#logger(logger) ⇒ Object
Returns the value of attribute logger.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#wait_strategy ⇒ Object
Returns the value of attribute wait_strategy.
Instance Method Summary collapse
- #fail_silently ⇒ Object
- #fail_silently? ⇒ Boolean
-
#initialize(&block) ⇒ PolicyBuilder
constructor
A new instance of PolicyBuilder.
- #measure_time_in(time_unit) ⇒ Object
- #never_give_up ⇒ Object
- #never_give_up? ⇒ Boolean
- #only_on_exceptions(exception_array) ⇒ Object
- #strategy ⇒ Object
- #timeout_after(retry_timeout) ⇒ Object
- #times(retry_count) ⇒ Object
- #valid_exception?(exception) ⇒ Boolean
- #wait ⇒ Object
- #with_strategy(wait_strategy, *args) ⇒ Object
Constructor Details
#initialize(&block) ⇒ PolicyBuilder
Returns a new instance of PolicyBuilder.
5 6 7 8 9 10 |
# File 'lib/greenjaguar/policy_builder.rb', line 5 def initialize(&block) @count = 1 @timeout = 300 @exceptions = [] instance_eval(&block) end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'lib/greenjaguar/policy_builder.rb', line 3 def count @count end |
#exceptions ⇒ Object
Returns the value of attribute exceptions.
3 4 5 |
# File 'lib/greenjaguar/policy_builder.rb', line 3 def exceptions @exceptions end |
#logger(logger) ⇒ Object
Returns the value of attribute logger.
3 4 5 |
# File 'lib/greenjaguar/policy_builder.rb', line 3 def logger @logger end |
#timeout ⇒ Object
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/greenjaguar/policy_builder.rb', line 3 def timeout @timeout end |
#wait_strategy ⇒ Object
Returns the value of attribute wait_strategy.
3 4 5 |
# File 'lib/greenjaguar/policy_builder.rb', line 3 def wait_strategy @wait_strategy end |
Instance Method Details
#fail_silently ⇒ Object
27 28 29 |
# File 'lib/greenjaguar/policy_builder.rb', line 27 def fail_silently @fail_silently = true end |
#fail_silently? ⇒ Boolean
31 32 33 |
# File 'lib/greenjaguar/policy_builder.rb', line 31 def fail_silently? @fail_silently end |
#measure_time_in(time_unit) ⇒ Object
43 44 45 46 |
# File 'lib/greenjaguar/policy_builder.rb', line 43 def measure_time_in(time_unit) strategy.time_unit = time_unit self end |
#never_give_up ⇒ Object
35 36 37 |
# File 'lib/greenjaguar/policy_builder.rb', line 35 def never_give_up @count = -1 end |
#never_give_up? ⇒ Boolean
39 40 41 |
# File 'lib/greenjaguar/policy_builder.rb', line 39 def never_give_up? @count == -1 end |
#only_on_exceptions(exception_array) ⇒ Object
53 54 55 |
# File 'lib/greenjaguar/policy_builder.rb', line 53 def only_on_exceptions(exception_array) @exceptions.concat exception_array end |
#strategy ⇒ Object
70 71 72 |
# File 'lib/greenjaguar/policy_builder.rb', line 70 def strategy @strategy ||= init_wait_strategy(:default) end |
#timeout_after(retry_timeout) ⇒ Object
17 18 19 20 |
# File 'lib/greenjaguar/policy_builder.rb', line 17 def timeout_after(retry_timeout) @timeout = retry_timeout self end |
#times(retry_count) ⇒ Object
12 13 14 15 |
# File 'lib/greenjaguar/policy_builder.rb', line 12 def times(retry_count) @count = retry_count self end |
#valid_exception?(exception) ⇒ Boolean
57 58 59 60 61 62 63 64 |
# File 'lib/greenjaguar/policy_builder.rb', line 57 def valid_exception?(exception) if @exceptions.empty? return true else @exceptions.each {|ex| return true if exception.class <= ex} end false end |
#wait ⇒ Object
66 67 68 |
# File 'lib/greenjaguar/policy_builder.rb', line 66 def wait strategy.wait end |
#with_strategy(wait_strategy, *args) ⇒ Object
48 49 50 51 |
# File 'lib/greenjaguar/policy_builder.rb', line 48 def with_strategy(wait_strategy, *args) @strategy = init_wait_strategy(wait_strategy, *args) self end |