Class: Mack::Routes::RouteMap::Route

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

Overview

regex_from_pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_pattern, regex_pattern, method, options) ⇒ Route

Returns a new instance of Route.



261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/routing/route_map.rb', line 261

def initialize(original_pattern, regex_pattern, method, options)
  self.original_pattern = original_pattern
  self.regex_pattern = regex_pattern
  self.method = method
  self.options = options
  self.embedded_parameters = []
  # find out where the embedded_parameters are:
  original_pattern.split("/").each_with_index do |seg, ind|
    if seg.match(/^:/)
      self.embedded_parameters[ind] = seg[1..seg.length].to_sym
    end
  end
end

Instance Attribute Details

#embedded_parametersObject

Returns the value of attribute embedded_parameters.



259
260
261
# File 'lib/routing/route_map.rb', line 259

def embedded_parameters
  @embedded_parameters
end

#methodObject

Returns the value of attribute method.



256
257
258
# File 'lib/routing/route_map.rb', line 256

def method
  @method
end

#optionsObject

Returns the value of attribute options.



258
259
260
# File 'lib/routing/route_map.rb', line 258

def options
  @options
end

#original_patternObject

Returns the value of attribute original_pattern.



257
258
259
# File 'lib/routing/route_map.rb', line 257

def original_pattern
  @original_pattern
end

#regex_patternObject

:nodoc:



255
256
257
# File 'lib/routing/route_map.rb', line 255

def regex_pattern
  @regex_pattern
end

Instance Method Details

#options_with_embedded_parameters(uri) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/routing/route_map.rb', line 275

def options_with_embedded_parameters(uri)
  opts = {:format => :html}.merge(self.options)
  m = uri.match(/\..+$/)
  if m
    m = m.to_s
    opts[:format]= m[1..m.size].to_sym
    uri.gsub!(/\..+$/, "")
  end
  split_uri = uri.split("/")
  self.embedded_parameters.each_with_index do |val, ind|
    unless val.nil?
      opts[val] = split_uri[ind]
    end
  end
  opts
end