lib/grape/router.rb in grape-0.16.2 vs lib/grape/router.rb in grape-0.17.0
- old
+ new
@@ -9,10 +9,18 @@
@pattern = pattern
super(attributes)
end
end
+ def self.normalize_path(path)
+ path = "/#{path}"
+ path.squeeze!('/')
+ path.sub!(%r{/+\Z}, '')
+ path = '/' if path == ''
+ path
+ end
+
def initialize
@neutral_map = []
@map = Hash.new { |hash, key| hash[key] = [] }
@optimized_map = Hash.new { |hash, key| hash[key] = // }
end
@@ -123,21 +131,12 @@
last_match = Regexp.last_match
@neutral_map.detect { |route| last_match["_#{route.index}"] }
end
def method_not_allowed(env, methods, endpoint)
- env[Grape::Env::GRAPE_METHOD_NOT_ALLOWED] = true
- current = endpoint.dup
- current.instance_eval do
- @lazy_initialized = false
- lazy_initialize!
- run_filters befores, :before
- @block = proc do
- fail Grape::Exceptions::MethodNotAllowed, header.merge('Allow' => methods)
- end
- end
- current.call(env)
+ env[Grape::Env::GRAPE_METHOD_NOT_ALLOWED] = methods
+ endpoint.call(env)
end
def cascade?(response)
response && response[1][Grape::Http::Headers::X_CASCADE] == 'pass'
end
@@ -146,16 +145,8 @@
map[method] + map['ANY']
end
def string_for(input)
self.class.normalize_path(input)
- end
-
- def self.normalize_path(path)
- path = "/#{path}"
- path.squeeze!('/')
- path.sub!(%r{/+\Z}, '')
- path = '/' if path == ''
- path
end
end
end