mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
Use Mustermann internally for building prefixed_path
as RegexpBased
pattern
Removed `regexpify` from internal API.
This commit is contained in:
parent
fb9a93ed06
commit
d6e1745ee7
2 changed files with 4 additions and 14 deletions
|
@ -201,7 +201,7 @@ module Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
def error(*codes, &block)
|
def error(*codes, &block)
|
||||||
args = Sinatra::Base.send(:compile!, "ERROR", regexpify(@pattern), block)
|
args = Sinatra::Base.send(:compile!, "ERROR", @pattern, block)
|
||||||
codes = codes.map { |c| Array(c) }.flatten
|
codes = codes.map { |c| Array(c) }.flatten
|
||||||
codes << Exception if codes.empty?
|
codes << Exception if codes.empty?
|
||||||
|
|
||||||
|
@ -266,16 +266,7 @@ module Sinatra
|
||||||
|
|
||||||
def prefixed_path(a, b)
|
def prefixed_path(a, b)
|
||||||
return a || b || // unless a and b
|
return a || b || // unless a and b
|
||||||
a, b = regexpify(a), regexpify(b) unless a.class == b.class
|
Mustermann.new(a.to_s + b.to_s, type: :regular)
|
||||||
path = a.class.new "#{a}#{b}"
|
|
||||||
path = /^#{path}$/ if path.is_a? Regexp and base == app
|
|
||||||
path
|
|
||||||
end
|
|
||||||
|
|
||||||
def regexpify(pattern)
|
|
||||||
pattern = Sinatra::Base.send(:compile, pattern).first.inspect
|
|
||||||
pattern.gsub! /^\/(\^|\\A)?|(\$|\\z)?\/$/, ''
|
|
||||||
Regexp.new pattern
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prefixed(method, pattern = nil, conditions = {}, &block)
|
def prefixed(method, pattern = nil, conditions = {}, &block)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Sinatra::Namespace do
|
describe Sinatra::Namespace do
|
||||||
verbs = [:get, :head, :post, :put, :delete, :options]
|
verbs = [:get, :head, :post, :put, :delete, :options, :patch]
|
||||||
verbs << :patch if Sinatra::VERSION >= '1.3'
|
|
||||||
|
|
||||||
def mock_app(&block)
|
def mock_app(&block)
|
||||||
super do
|
super do
|
||||||
|
@ -689,7 +688,7 @@ describe Sinatra::Namespace do
|
||||||
end
|
end
|
||||||
get('/bar') { }
|
get('/bar') { }
|
||||||
end
|
end
|
||||||
route[1].should eq '/foo'
|
route[1].should eq Mustermann.new '/foo', type: :regular
|
||||||
end
|
end
|
||||||
|
|
||||||
specify 'prevent app-global settings from being changed' do
|
specify 'prevent app-global settings from being changed' do
|
||||||
|
|
Loading…
Reference in a new issue