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.



7
8
9
# File 'lib/fake_web/registry.rb', line 7

def initialize
  clean_registry
end

Instance Attribute Details

#passthrough_uri_mapObject

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_mapObject

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_registryObject



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

Returns:

  • (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, options)
  uri_map[normalize_uri(uri)][method] = [*[options]].flatten.collect do |option|
    FakeWeb::Responder.new(method, uri, option, option[:times])
  end
end

#registered_uri?(method, uri) ⇒ Boolean

Returns:

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



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