Class: FakeWeb::Registry
- Inherits:
-
Object
- Object
- FakeWeb::Registry
- Includes:
- Singleton
- Defined in:
- lib/fake_web/registry.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#passthrough_uri_map ⇒ Object
Returns the value of attribute passthrough_uri_map.
-
#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.
- #passthrough_uri_matches?(uri) ⇒ Boolean
- #register_passthrough_uri(uri) ⇒ Object
- #register_uri(method, uri, options) ⇒ Object
- #registered_uri?(method, uri) ⇒ Boolean
- #remove_passthrough_uri ⇒ Object
- #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
#passthrough_uri_map ⇒ Object
Returns the value of attribute passthrough_uri_map.
5 6 7 |
# File 'lib/fake_web/registry.rb', line 5 def passthrough_uri_map @passthrough_uri_map end |
#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 |
#passthrough_uri_matches?(uri) ⇒ Boolean
49 50 51 52 53 |
# File 'lib/fake_web/registry.rb', line 49 def passthrough_uri_matches?(uri) uri = normalize_uri(uri) uri_map_matches(passthrough_uri_map, :any, uri, URI) || uri_map_matches(passthrough_uri_map, :any, uri, Regexp) end |
#register_passthrough_uri(uri) ⇒ Object
41 42 43 |
# File 'lib/fake_web/registry.rb', line 41 def register_passthrough_uri(uri) self.passthrough_uri_map = {normalize_uri(uri) => {:any => true}} 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 |
#remove_passthrough_uri ⇒ Object
45 46 47 |
# File 'lib/fake_web/registry.rb', line 45 def remove_passthrough_uri self.passthrough_uri_map = {} 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(&block) end |