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.
9 10 11 |
# File 'lib/fake_web/registry.rb', line 9 def initialize clean_registry end |
Instance Attribute Details
#passthrough_uri_map ⇒ Object
Returns the value of attribute passthrough_uri_map.
7 8 9 |
# File 'lib/fake_web/registry.rb', line 7 def passthrough_uri_map @passthrough_uri_map end |
#uri_map ⇒ Object
Returns the value of attribute uri_map.
7 8 9 |
# File 'lib/fake_web/registry.rb', line 7 def uri_map @uri_map end |
Instance Method Details
#clean_registry ⇒ Object
13 14 15 |
# File 'lib/fake_web/registry.rb', line 13 def clean_registry self.uri_map = Hash.new { |hash, key| hash[key] = {} } end |
#passthrough_uri_matches?(uri) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/fake_web/registry.rb', line 54 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
46 47 48 |
# File 'lib/fake_web/registry.rb', line 46 def register_passthrough_uri(uri) self.passthrough_uri_map = {normalize_uri(uri) => {:any => true}} end |
#register_uri(method, uri, options) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/fake_web/registry.rb', line 17 def register_uri(method, uri, ) uri_map[normalize_uri(uri)][method] = [*[]].flatten.collect do |option| if !option.respond_to?(:keys) raise ArgumentError.new("Expected options hash: #{option.inspect}") end FakeWeb::Responder.new(method, uri, option, option[:times]) end end |
#registered_uri?(method, uri) ⇒ Boolean
26 27 28 |
# File 'lib/fake_web/registry.rb', line 26 def registered_uri?(method, uri) !responders_for(method, uri).empty? end |
#remove_passthrough_uri ⇒ Object
50 51 52 |
# File 'lib/fake_web/registry.rb', line 50 def remove_passthrough_uri self.passthrough_uri_map = {} end |
#response_for(method, uri, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fake_web/registry.rb', line 30 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 |