Class: Mack::Routes::RouteObject
- Defined in:
- lib/mack/routing/route_object.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#deferred ⇒ Object
Returns the value of attribute deferred.
-
#embedded_parameters ⇒ Object
Returns the value of attribute embedded_parameters.
-
#insertion_order ⇒ Object
Returns the value of attribute insertion_order.
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#regex_patterns ⇒ Object
Returns the value of attribute regex_patterns.
-
#wildcard ⇒ Object
Returns the value of attribute wildcard.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(path, options = {}) ⇒ RouteObject
constructor
A new instance of RouteObject.
- #match?(env = {}) ⇒ Boolean
- #options_with_parameters(url, host = nil) ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ RouteObject
Returns a new instance of RouteObject.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mack/routing/route_object.rb', line 14 def initialize(path, = {}) self.path = path self. = {:action => :index}.merge() self.deferred = self..delete(:deferred?) || false # self.embedded_parameters = [] # self.host_embedded_parameters = [] self.regex_patterns = {} self. = {:uri => [], :host => []} build_regex_patterns self.insertion_order = Mack::Routes::RouteObject.next_insertion_index end |
Instance Attribute Details
#deferred ⇒ Object
Returns the value of attribute deferred.
12 13 14 |
# File 'lib/mack/routing/route_object.rb', line 12 def deferred @deferred end |
#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 |
#insertion_order ⇒ Object
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 |
#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_patterns ⇒ Object
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 |
#wildcard ⇒ Object
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
72 73 74 |
# File 'lib/mack/routing/route_object.rb', line 72 def <=>(other) self.insertion_order <=> other.insertion_order end |
#==(other) ⇒ Object
27 28 29 |
# File 'lib/mack/routing/route_object.rb', line 27 def ==(other) self. == other end |
#match?(env = {}) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mack/routing/route_object.rb', line 31 def match?(env = {}) if self.[:host] return false unless !env[:host].nil? && env[:host].match(self.regex_patterns[:host]) end if self.[:scheme] return false unless !env[:scheme].nil? && self.[:scheme].downcase == env[:scheme] end if self.[:port] return false unless !env[:port].nil? && self.[:port].to_i == env[:port].to_i end if env[:uri].downcase.match(self.regex_patterns[:uri]) if self.[:format] format = (File.extname(env[:uri]).blank? ? '.html' : File.extname(env[:uri])) format = format[1..format.length] return format.to_sym == self.[:format] end return true end return false end |
#options_with_parameters(url, host = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mack/routing/route_object.rb', line 52 def (url, host = nil) format = (File.extname(url).blank? ? '.html' : File.extname(url)) format = format[1..format.length] opts = self..merge(:format => format) url = url.gsub(/\.#{format}$/, '') opts.merge!((:uri, url, '/')) unless host.nil? opts.merge!((:host, host, '.')) opts.merge!(:host => host) if self.[: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 |