Class: FakeWeb::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fake_web/registry.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

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_mapObject

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_mapObject

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_registryObject



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

Returns:

  • (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, options)
  uri_map[normalize_uri(uri)][method] = [*[options]].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

Returns:

  • (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_uriObject



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