Class: FakeWeb::Registry
- Inherits:
-
Object
- Object
- FakeWeb::Registry
- Includes:
- Singleton
- Defined in:
- lib/fake_web/registry.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#uri_map ⇒ Object
Returns the value of attribute uri_map.
Instance Method Summary collapse
- #clean_registry ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register_uri(method, uri, options) ⇒ Object
- #registered_uri?(method, uri) ⇒ Boolean
- #response_for(method, uri, &block) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
7 8 9 |
# File 'lib/fake_web/registry.rb', line 7 def initialize clean_registry end |
Instance Attribute Details
#uri_map ⇒ Object
Returns the value of attribute uri_map.
5 6 7 |
# File 'lib/fake_web/registry.rb', line 5 def uri_map @uri_map end |
Instance Method Details
#clean_registry ⇒ Object
11 12 13 |
# File 'lib/fake_web/registry.rb', line 11 def clean_registry self.uri_map = Hash.new { |hash, key| hash[key] = {} } end |
#register_uri(method, uri, options) ⇒ Object
15 16 17 18 19 |
# File 'lib/fake_web/registry.rb', line 15 def register_uri(method, uri, ) uri_map[normalize_uri(uri)][method] = [*[]].flatten.collect do |option| FakeWeb::Responder.new(method, uri, option, option[:times]) end end |
#registered_uri?(method, uri) ⇒ Boolean
21 22 23 |
# File 'lib/fake_web/registry.rb', line 21 def registered_uri?(method, uri) !responders_for(method, uri).empty? end |
#response_for(method, uri, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fake_web/registry.rb', line 25 def response_for(method, uri, &block) responders = responders_for(method, uri) return nil if responders.empty? next_responder = responders.last responders.each do |responder| if responder.times and responder.times > 0 responder.times -= 1 next_responder = responder break end end next_responder.response(uri, &block) end |