Class: Confinement::RouteIdentifiers

Inherits:
Object
  • Object
show all
Defined in:
lib/confinement.rb

Overview

RouteIdentifiers is called such because it doesn’t hold the actual content’s route. The content’s own url_path does.

This is mainly so that assets could be referenced internally with a static identifier even though it could have a hashed route.

Instance Method Summary collapse

Constructor Details

#initializeRouteIdentifiers



193
194
195
# File 'lib/confinement.rb', line 193

def initialize
  self.lookup = {}
end

Instance Method Details

#[](route) ⇒ Object



201
202
203
204
205
206
207
208
209
# File 'lib/confinement.rb', line 201

def [](route)
  route = route.normalize_for_route

  if !lookup.key?(route)
    raise "Route is not defined"
  end

  self.lookup[route]
end

#[]=(route, content) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/confinement.rb', line 211

def []=(route, content)
  raise "Can't add more routes after initial setup" if @done

  route = route.normalize_for_route

  if lookup.key?(route)
    raise "Route already defined!"
  end

  content.url_path = route

  lookup[route] = content
end

#done!Object



197
198
199
# File 'lib/confinement.rb', line 197

def done!
  @done = true
end