lib/grape/api.rb in grape-0.7.0 vs lib/grape/api.rb in grape-0.8.0
- old
+ new
@@ -97,11 +97,11 @@
if args.any?
options = args.pop if args.last.is_a? Hash
options ||= {}
options = { using: :path }.merge(options)
- raise Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.has_key?(:vendor)
+ raise Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.key?(:vendor)
@versions = versions | args
nest(block) do
set(:version, args)
set(:version_options, options)
@@ -157,11 +157,11 @@
settings[:default_error_formatter]
end
end
def error_formatter(format, options)
- if options.is_a?(Hash) && options.has_key?(:with)
+ if options.is_a?(Hash) && options.key?(:with)
formatter = options[:with]
else
formatter = options
end
@@ -210,18 +210,28 @@
elsif block_given?
handler = block
end
options = args.last.is_a?(Hash) ? args.pop : {}
- handler ||= proc { options[:with] } if options.has_key?(:with)
+ handler ||= proc { options[:with] } if options.key?(:with)
- handler_type = !!options[:rescue_subclasses] ? :rescue_handlers : :base_only_rescue_handlers
- imbue handler_type, Hash[args.map { |arg| [arg, handler] }]
+ if args.include?(:all)
+ set(:rescue_all, true)
+ imbue :all_rescue_handler, handler
+ else
+ handler_type =
+ case options[:rescue_subclasses]
+ when nil, true
+ :rescue_handlers
+ else
+ :base_only_rescue_handlers
+ end
- imbue(:rescue_options, options)
+ imbue handler_type, Hash[args.map { |arg| [arg, handler] }]
+ end
- set(:rescue_all, true) if args.include?(:all)
+ imbue(:rescue_options, options)
end
# Allows you to specify a default representation entity for a
# class. This allows you to map your models to their respective
# entities once and then simply call `present` with the model.
@@ -470,11 +480,11 @@
@versions ||= []
end
def cascade(value = nil)
if value.nil?
- settings.has_key?(:cascade) ? !!settings[:cascade] : true
+ settings.key?(:cascade) ? !!settings[:cascade] : true
else
set(:cascade, value)
end
end
@@ -546,12 +556,12 @@
#
# In some applications (e.g. mounting grape on rails), one might need to trap
# errors from reaching upstream. This is effectivelly done by unsetting
# X-Cascade. Default :cascade is true.
def cascade?
- return !!self.class.settings[:cascade] if self.class.settings.has_key?(:cascade)
- return !!self.class.settings[:version_options][:cascade] if self.class.settings[:version_options] && self.class.settings[:version_options].has_key?(:cascade)
+ return !!self.class.settings[:cascade] if self.class.settings.key?(:cascade)
+ return !!self.class.settings[:version_options][:cascade] if self.class.settings[:version_options] && self.class.settings[:version_options].key?(:cascade)
true
end
reset!
@@ -577,12 +587,10 @@
# informations again.
without_versioning do
methods_per_path.each do |path, methods|
allowed_methods = methods.dup
unless self.class.settings[:do_not_route_head]
- if allowed_methods.include?('GET')
- allowed_methods = allowed_methods | ['HEAD']
- end
+ allowed_methods |= ['HEAD'] if allowed_methods.include?('GET')
end
allow_header = (['OPTIONS'] | allowed_methods).join(', ')
unless self.class.settings[:do_not_route_options]
unless allowed_methods.include?('OPTIONS')