Class: Sinatra::Trails::ScopeMatcher
- Inherits:
-
Object
- Object
- Sinatra::Trails::ScopeMatcher
- Defined in:
- lib/sinatra/trails.rb
Overview
This is hackish
Instance Method Summary collapse
- #actual_keys ⇒ Object
- #any? ⇒ Boolean
-
#initialize(scope, matchers) ⇒ ScopeMatcher
constructor
A new instance of ScopeMatcher.
- #keys ⇒ Object
- #match(str) ⇒ Object
- #routes ⇒ Object
- #to_regexp ⇒ Object
- #zip(arr) ⇒ Object
Constructor Details
#initialize(scope, matchers) ⇒ ScopeMatcher
Returns a new instance of ScopeMatcher.
66 67 68 69 |
# File 'lib/sinatra/trails.rb', line 66 def initialize scope, matchers @scope = scope @names, @matchers = matchers.partition { |el| Symbol === el } end |
Instance Method Details
#actual_keys ⇒ Object
88 89 90 |
# File 'lib/sinatra/trails.rb', line 88 def actual_keys @actual_keys ||= routes.map{ |m| m.keys }.flatten end |
#any? ⇒ Boolean
93 |
# File 'lib/sinatra/trails.rb', line 93 def any?() actual_keys.any? end |
#keys ⇒ Object
92 |
# File 'lib/sinatra/trails.rb', line 92 def keys() self end |
#match(str) ⇒ Object
71 72 73 |
# File 'lib/sinatra/trails.rb', line 71 def match str to_regexp.match str end |
#routes ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/sinatra/trails.rb', line 79 def routes @routes ||= if @matchers.empty? && @names.empty? @scope.routes else @matchers + @names.map { |name| @scope[name] } end end |
#to_regexp ⇒ Object
75 76 77 |
# File 'lib/sinatra/trails.rb', line 75 def to_regexp @to_regexp ||= Regexp.union(routes) end |
#zip(arr) ⇒ Object
94 |
# File 'lib/sinatra/trails.rb', line 94 def zip(arr) actual_keys.zip(arr) end |