Class: Innate::URLMap

Inherits:
Rack::URLMap
  • Object
show all
Defined in:
lib/innate/dynamap.rb

Instance Method Summary collapse

Constructor Details

#initialize(map = {}) ⇒ URLMap

Returns a new instance of URLMap.



3
4
5
6
# File 'lib/innate/dynamap.rb', line 3

def initialize(map = {})
  @originals = map
  super
end

Instance Method Details

#at(location) ⇒ Object



21
22
23
# File 'lib/innate/dynamap.rb', line 21

def at(location)
  @originals[location]
end

#call(env) ⇒ Object



33
34
35
36
# File 'lib/innate/dynamap.rb', line 33

def call(env)
  raise "Nothing mapped yet" if @originals.empty?
  super
end

#map(location, object) ⇒ Object



16
17
18
19
# File 'lib/innate/dynamap.rb', line 16

def map(location, object)
  return unless location and object
  remap(@originals.merge(location.to_s => object))
end

#remap(map) ⇒ Object

super may raise when given invalid locations, so we only replace the ‘@originals` if we are sure the new map is valid



10
11
12
13
14
# File 'lib/innate/dynamap.rb', line 10

def remap(map)
  value = super
  @originals = map
  value
end

#to(object) ⇒ Object



25
26
27
# File 'lib/innate/dynamap.rb', line 25

def to(object)
  @originals.invert[object]
end

#to_hashObject



29
30
31
# File 'lib/innate/dynamap.rb', line 29

def to_hash
  @originals.dup
end