Class: Klepto::Config
- Inherits:
-
Object
- Object
- Klepto::Config
- Defined in:
- lib/klepto/config.rb
Instance Attribute Summary collapse
-
#after_handlers ⇒ Object
readonly
Returns the value of attribute after_handlers.
-
#before_handlers ⇒ Object
readonly
Returns the value of attribute before_handlers.
Instance Method Summary collapse
-
#abort_on_failure(aof) ⇒ Object
4xx, 5xx.
- #abort_on_failure? ⇒ Boolean
- #abort_on_redirect(aor) ⇒ Object
- #abort_on_redirect? ⇒ Boolean
- #after(which = :structure, &block) ⇒ Object
- #before(which, &block) ⇒ Object
- #has_timeout_handler? ⇒ Boolean
-
#headers(_headers = nil) ⇒ Object
def driver(_driver=nil) @default_driver = _driver if _driver @default_driver end.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #on_http_status(*statuses, &block) ⇒ Object
- #on_http_timeout(&block) ⇒ Object
- #status_handler(status) ⇒ Object
- #url(url = nil) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/klepto/config.rb', line 6 def initialize @headers = {} @abort_on_failure = true @abort_on_redirect = false @after_handlers = { :structure => [], #after each call to :get => [], #after GET, before structure :abort=> [] #after abort } @before_handlers = {:get => []} @status_handlers = {} @handlers = {} end |
Instance Attribute Details
#after_handlers ⇒ Object (readonly)
Returns the value of attribute after_handlers.
3 4 5 |
# File 'lib/klepto/config.rb', line 3 def after_handlers @after_handlers end |
#before_handlers ⇒ Object (readonly)
Returns the value of attribute before_handlers.
4 5 6 |
# File 'lib/klepto/config.rb', line 4 def before_handlers @before_handlers end |
Instance Method Details
#abort_on_failure(aof) ⇒ Object
4xx, 5xx
50 51 52 |
# File 'lib/klepto/config.rb', line 50 def abort_on_failure(aof) @abort_on_failure = aof end |
#abort_on_failure? ⇒ Boolean
41 42 43 |
# File 'lib/klepto/config.rb', line 41 def abort_on_failure? !!@abort_on_failure end |
#abort_on_redirect(aor) ⇒ Object
54 55 56 |
# File 'lib/klepto/config.rb', line 54 def abort_on_redirect(aor) @abort_on_redirect = aor end |
#abort_on_redirect? ⇒ Boolean
45 46 47 |
# File 'lib/klepto/config.rb', line 45 def abort_on_redirect? !!@abort_on_redirect end |
#after(which = :structure, &block) ⇒ Object
74 75 76 77 |
# File 'lib/klepto/config.rb', line 74 def after(which = :structure, &block) @after_handlers[which] ||= [] @after_handlers[which].push block end |
#before(which, &block) ⇒ Object
79 80 81 82 |
# File 'lib/klepto/config.rb', line 79 def before(which, &block) @before_handlers[which] ||= [] @before_handlers[which].push block end |
#has_timeout_handler? ⇒ Boolean
37 38 39 |
# File 'lib/klepto/config.rb', line 37 def has_timeout_handler? @status_handlers[:timeout] && @status_handlers[:timeout].any? end |
#headers(_headers = nil) ⇒ Object
def driver(_driver=nil)
@default_driver = _driver if _driver
@default_driver
end
32 33 34 35 |
# File 'lib/klepto/config.rb', line 32 def headers(_headers=nil) @headers = _headers if _headers @headers end |
#on_http_status(*statuses, &block) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/klepto/config.rb', line 67 def on_http_status(*statuses,&block) statuses.each do |status| @status_handlers[status] ||= [] @status_handlers[status].push block end end |
#on_http_timeout(&block) ⇒ Object
62 63 64 65 |
# File 'lib/klepto/config.rb', line 62 def on_http_timeout(&block) @status_handlers[:timeout] ||= [] @status_handlers[:timeout].push block end |
#status_handler(status) ⇒ Object
58 59 60 |
# File 'lib/klepto/config.rb', line 58 def status_handler(status) @status_handlers[status] || [] end |
#url(url = nil) ⇒ Object
84 85 86 87 |
# File 'lib/klepto/config.rb', line 84 def url(url=nil) @url = url if url @url end |