Class: Sinatra::Trails::ScopeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/trails.rb

Overview

This is hackish

Instance Method Summary collapse

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_keysObject



88
89
90
# File 'lib/sinatra/trails.rb', line 88

def actual_keys
  @actual_keys ||= routes.map{ |m| m.keys }.flatten
end

#any?Boolean

Returns:

  • (Boolean)


93
# File 'lib/sinatra/trails.rb', line 93

def any?() actual_keys.any? end

#keysObject



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

#routesObject



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_regexpObject



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