Class: Opencdd::Cddal::Fetcher::InMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/cddal/fetcher/in_memory.rb

Overview

Test fetcher. Holds an in-memory URL → source map; specs construct one with the fixtures they want to serve. Avoids any network dependency in the test suite.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map = {}) ⇒ InMemory

Returns a new instance of InMemory.



12
13
14
15
# File 'lib/opencdd/cddal/fetcher/in_memory.rb', line 12

def initialize(map = {})
  @map = {}
  map.each { |k, v| @map[k.to_s] = v.to_s }
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map.



10
11
12
# File 'lib/opencdd/cddal/fetcher/in_memory.rb', line 10

def map
  @map
end

Instance Method Details

#fetch(url) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/opencdd/cddal/fetcher/in_memory.rb', line 17

def fetch(url)
  key = url.to_s
  @map.fetch(key) do
    raise Opencdd::Cddal::ImportError,
          "no in-memory fixture registered for #{key}"
  end
end

#register(url, source) ⇒ Object



25
26
27
28
# File 'lib/opencdd/cddal/fetcher/in_memory.rb', line 25

def register(url, source)
  @map[url.to_s] = source.to_s
  self
end