Class: Groem::Route
- Inherits:
-
Object
- Object
- Groem::Route
- Defined in:
- lib/groem/route.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
sort nil parts after named parts (unless named parts begin with ~).
-
#initialize(action, *path) ⇒ Route
constructor
A new instance of Route.
- #matches?(*args) ⇒ Boolean
Constructor Details
#initialize(action, *path) ⇒ Route
Returns a new instance of Route.
21 22 23 24 |
# File 'lib/groem/route.rb', line 21 def initialize action, *path path = path.flatten @pattern = self.class.parse action, *path end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
19 20 21 |
# File 'lib/groem/route.rb', line 19 def pattern @pattern end |
Class Method Details
.matches?(pattern, parts) ⇒ Boolean
10 11 12 13 14 15 |
# File 'lib/groem/route.rb', line 10 def matches? pattern, parts parts = [parts] unless Array === parts pattern.zip(parts).all? do |exp, act| exp.nil? || exp == act end end |
.parse(action, *path) ⇒ Object
6 7 8 |
# File 'lib/groem/route.rb', line 6 def parse action, *path [action] + Array.new(2).fill {|i| path[i] } end |
Instance Method Details
#<=>(other) ⇒ Object
sort nil parts after named parts (unless named parts begin with ~)
32 33 34 |
# File 'lib/groem/route.rb', line 32 def <=>(other) pattern.map {|it| it || '~'} <=> other.pattern.map {|it| it || '~'} end |
#matches?(*args) ⇒ Boolean
26 27 28 |
# File 'lib/groem/route.rb', line 26 def matches?(*args) self.class.matches?(pattern, args.flatten) end |