lib/grape/dsl/inside_route.rb in grape-1.2.5 vs lib/grape/dsl/inside_route.rb in grape-1.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require 'active_support/concern'
require 'grape/dsl/headers'
module Grape
module DSL
@@ -26,11 +28,11 @@
# Methods which should not be available in filters until the before filter
# has completed
module PostBeforeFilter
def declared(passed_params, options = {}, declared_params = nil)
options = options.reverse_merge(include_missing: true, include_parent_namespaces: true)
- declared_params ||= optioned_declared_params(options)
+ declared_params ||= optioned_declared_params(**options)
if passed_params.is_a?(Array)
declared_array(passed_params, options, declared_params)
else
declared_hash(passed_params, options, declared_params)
@@ -82,22 +84,23 @@
def should_be_empty_array?(declared_param, passed_children_params)
declared_param_is_array?(declared_param) && passed_children_params.empty?
end
def declared_param_is_array?(declared_param)
- route_options_params[declared_param.to_s] && route_options_params[declared_param.to_s][:type] == 'Array'
+ key = declared_param.to_s
+ route_options_params[key] && route_options_params[key][:type] == 'Array'
end
def route_options_params
options[:route_options][:params] || {}
end
def optioned_param_key(declared_param, options)
options[:stringify] ? declared_param.to_s : declared_param.to_sym
end
- def optioned_declared_params(options)
+ def optioned_declared_params(**options)
declared_params = if options[:include_parent_namespaces]
# Declared params including parent namespaces
route_setting(:saved_declared_params).flatten | Array(route_setting(:declared_params))
else
# Declared params at current namespace
@@ -382,10 +385,10 @@
# @return the representation of the given object as done through
# the given entity_class.
def entity_representation_for(entity_class, object, options)
embeds = { env: env }
embeds[:version] = env[Grape::Env::API_VERSION] if env[Grape::Env::API_VERSION]
- entity_class.represent(object, embeds.merge(options))
+ entity_class.represent(object, **embeds.merge(options))
end
end
end
end