Class: Mack::Routes::RouteObject
- Inherits:
-
Object
- Object
- Mack::Routes::RouteObject
- Defined in:
- lib/mack/routing/route_object.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#embedded_parameters ⇒ Object
Returns the value of attribute embedded_parameters.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#regex_pattern ⇒ Object
Returns the value of attribute regex_pattern.
-
#wildcard ⇒ Object
Returns the value of attribute wildcard.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(path, options = {}) ⇒ RouteObject
constructor
A new instance of RouteObject.
- #match?(url) ⇒ Boolean
- #options_with_parameters(url) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ RouteObject
Returns a new instance of RouteObject.
12 13 14 15 16 17 |
# File 'lib/mack/routing/route_object.rb', line 12 def initialize(path, = {}) self.path = path self. = {:action => :index}.merge() self. = [] build_regex_pattern end |
Instance Attribute Details
#embedded_parameters ⇒ Object
Returns the value of attribute embedded_parameters.
9 10 11 |
# File 'lib/mack/routing/route_object.rb', line 9 def @embedded_parameters end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/mack/routing/route_object.rb', line 6 def @options end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/mack/routing/route_object.rb', line 7 def path @path end |
#regex_pattern ⇒ Object
Returns the value of attribute regex_pattern.
8 9 10 |
# File 'lib/mack/routing/route_object.rb', line 8 def regex_pattern @regex_pattern end |
#wildcard ⇒ Object
Returns the value of attribute wildcard.
10 11 12 |
# File 'lib/mack/routing/route_object.rb', line 10 def wildcard @wildcard end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/mack/routing/route_object.rb', line 19 def ==(other) self. == other end |
#match?(url) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mack/routing/route_object.rb', line 23 def match?(url) if url.downcase.match(self.regex_pattern) if self.[:format] format = (File.extname(url).blank? ? '.html' : File.extname(url)) format = format[1..format.length] return format.to_sym == self.[:format] end return true end return false end |
#options_with_parameters(url) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mack/routing/route_object.rb', line 35 def (url) format = (File.extname(url).blank? ? '.html' : File.extname(url)) format = format[1..format.length] opts = self..merge(:format => format) url = url.gsub(/\.#{format}$/, '') if self..any? url.split('/').each_with_index do |seg, i| ep = self.[i] unless ep.nil? opts[ep.to_sym] = seg end end end if self.wildcard caps = url.match(self.regex_pattern).captures if caps opts[self.wildcard.to_sym] = caps.first.split('/') end end opts end |