Class: Mack::Routes::RouteObject

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ RouteObject

Returns a new instance of RouteObject.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mack/routing/route_object.rb', line 13

def initialize(path, options = {})
  self.path = path
  self.options = {:action => :index}.merge(options)
  # self.embedded_parameters = []
  # self.host_embedded_parameters = []
  self.regex_patterns = {}
  self.embedded_parameters = {:uri => [], :host => []}
  build_regex_patterns
  
  self.insertion_order = Mack::Routes::RouteObject.next_insertion_index
end

Instance Attribute Details

#embedded_parametersObject

Returns the value of attribute embedded_parameters.



9
10
11
# File 'lib/mack/routing/route_object.rb', line 9

def embedded_parameters
  @embedded_parameters
end

#insertion_orderObject

Returns the value of attribute insertion_order.



11
12
13
# File 'lib/mack/routing/route_object.rb', line 11

def insertion_order
  @insertion_order
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/mack/routing/route_object.rb', line 6

def options
  @options
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/mack/routing/route_object.rb', line 7

def path
  @path
end

#regex_patternsObject

Returns the value of attribute regex_patterns.



10
11
12
# File 'lib/mack/routing/route_object.rb', line 10

def regex_patterns
  @regex_patterns
end

#wildcardObject

Returns the value of attribute wildcard.



8
9
10
# File 'lib/mack/routing/route_object.rb', line 8

def wildcard
  @wildcard
end

Instance Method Details

#<=>(other) ⇒ Object



61
62
63
# File 'lib/mack/routing/route_object.rb', line 61

def <=>(other)
  self.insertion_order <=> other.insertion_order
end

#==(other) ⇒ Object



25
26
27
# File 'lib/mack/routing/route_object.rb', line 25

def ==(other)
  self.options == other
end

#match?(url) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mack/routing/route_object.rb', line 29

def match?(url)
  if url.downcase.match(self.regex_patterns[:uri])
    if self.options[:format]
      format = (File.extname(url).blank? ? '.html' : File.extname(url))
      format = format[1..format.length]
      return format.to_sym == self.options[:format]
    end
    return true
  end
  return false
end

#options_with_parameters(url, host = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mack/routing/route_object.rb', line 41

def options_with_parameters(url, host = nil)
  format = (File.extname(url).blank? ? '.html' : File.extname(url))
  format = format[1..format.length]
  opts = self.options.merge(:format => format)
  url = url.gsub(/\.#{format}$/, '')
  opts.merge!(get_embedded_parameters(:uri, url, '/'))
  unless host.nil?
    opts.merge!(get_embedded_parameters(:host, host, '.'))
    opts.merge!(:host => host) if self.options[:host]
  end
  if self.wildcard
    caps = url.match(self.regex_patterns[:uri]).captures
    if caps
      opts[self.wildcard.to_sym] = caps.first.split('/')
    end
  end

  opts
end