Skip to content

Commit 0d35b76

Browse files
committed
rubocop autofix
1 parent b059a66 commit 0d35b76

9 files changed

+52
-71
lines changed

lib/apipie/application.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,7 @@ def json_schema_for_method_response(version, controller_name, method_name, retur
271271
.json_schema_for_method_response(method, return_code, allow_nulls)
272272
end
273273

274-
def json_schema_for_self_describing_class(cls, allow_nulls)
275-
Apipie::SwaggerGenerator
276-
.json_schema_for_self_describing_class(cls, allow_nulls)
277-
end
274+
delegate :json_schema_for_self_describing_class, to: :'Apipie::SwaggerGenerator'
278275

279276
def to_swagger_json(version, resource_id, method_name, language, clear_warnings = false)
280277
return unless valid_search_args?(version, resource_id, method_name)

lib/apipie/dsl_definition.rb

+41-43
Original file line numberDiff line numberDiff line change
@@ -230,63 +230,61 @@ def tags(*args)
230230
def _apipie_define_validators(description)
231231

232232
# [re]define method only if validation is turned on
233-
if description && (Apipie.configuration.validate == true ||
234-
Apipie.configuration.validate == :implicitly ||
235-
Apipie.configuration.validate == :explicitly)
236-
237-
_apipie_save_method_params(description.method, description.params)
238-
239-
unless instance_methods.include?(:apipie_validations)
240-
define_method(:apipie_validations) do
241-
method_params = self.class._apipie_get_method_params(action_name)
242-
243-
if Apipie.configuration.validate_presence?
244-
Validator::BaseValidator.raise_if_missing_params do |missing|
245-
method_params.each_value do |param|
246-
# check if required parameters are present
247-
missing << param if param.required && !params.key?(param.name)
248-
end
249-
end
250-
end
233+
return unless description && [true, :implicitly, :explicitly].include?(Apipie.configuration.validate)
234+
235+
_apipie_save_method_params(description.method, description.params)
251236

252-
if Apipie.configuration.validate_value?
237+
unless instance_methods.include?(:apipie_validations)
238+
define_method(:apipie_validations) do
239+
method_params = self.class._apipie_get_method_params(action_name)
240+
241+
if Apipie.configuration.validate_presence?
242+
Validator::BaseValidator.raise_if_missing_params do |missing|
253243
method_params.each_value do |param|
254-
# params validations
255-
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
244+
# check if required parameters are present
245+
missing << param if param.required && !params.key?(param.name)
256246
end
257247
end
248+
end
258249

259-
# Only allow params passed in that are defined keys in the api
260-
# Auto skip the default params (format, controller, action)
261-
if Apipie.configuration.validate_key?
262-
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.each_pair do |param, _|
263-
# params allowed
264-
if method_params.none? {|_,p| p.name.to_s == param.to_s}
265-
self.class._apipie_handle_validate_key_error params, param
266-
end
267-
end
250+
if Apipie.configuration.validate_value?
251+
method_params.each_value do |param|
252+
# params validations
253+
param.validate(params[:"#{param.name}"]) if params.key?(param.name)
268254
end
255+
end
269256

270-
return unless Apipie.configuration.process_value?
271-
@api_params ||= {}
272-
method_params.each_value do |param|
273-
# params processing
274-
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
257+
# Only allow params passed in that are defined keys in the api
258+
# Auto skip the default params (format, controller, action)
259+
if Apipie.configuration.validate_key?
260+
params.reject{|k,_| %w[format controller action].include?(k.to_s) }.each_pair do |param, _|
261+
# params allowed
262+
if method_params.none? {|_,p| p.name.to_s == param.to_s}
263+
self.class._apipie_handle_validate_key_error params, param
264+
end
275265
end
276266
end
267+
268+
return unless Apipie.configuration.process_value?
269+
@api_params ||= {}
270+
method_params.each_value do |param|
271+
# params processing
272+
@api_params[param.as] = param.process_value(params[:"#{param.name}"]) if params.key?(param.name)
273+
end
277274
end
275+
end
278276

279-
if Apipie.configuration.validate == :implicitly || Apipie.configuration.validate == true
280-
old_method = instance_method(description.method)
277+
return unless [:implicitly, true].include?(Apipie.configuration.validate)
278+
old_method = instance_method(description.method)
281279

282-
define_method(description.method) do |*args|
283-
apipie_validations
280+
define_method(description.method) do |*args|
281+
apipie_validations
284282

285-
# run the original method code
286-
old_method.bind(self).call(*args)
287-
end
288-
end
283+
# run the original method code
284+
old_method.bind(self).call(*args)
289285
end
286+
287+
290288
end
291289

292290
def _apipie_handle_validate_key_error params, param

lib/apipie/extractor.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def finish
5454
end
5555
end
5656

57-
def logger
58-
Rails.logger
59-
end
57+
delegate :logger, to: :Rails
6058

6159
def call_recorder
6260
Thread.current[:apipie_call_recorder] ||= Recorder.new

lib/apipie/param_description.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def initialize(method_description, name, validator, desc_or_options = nil, optio
8787
action_awareness
8888

8989
if validator
90-
if (validator != Hash) && (validator.is_a? Hash) && (validator[:array_of])
90+
if (validator != Hash) && (validator.is_a? Hash) && validator[:array_of]
9191
@is_array = true
9292
validator = validator[:array_of]
9393
raise "an ':array_of =>' validator is allowed exclusively on response-only fields" unless @response_only

lib/apipie/response_description.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,13 @@ def is_array?
119119
@is_array_of != false
120120
end
121121

122-
def typename
123-
@response_object.typename
124-
end
122+
delegate :typename, to: :@response_object
125123

126124
def param_description
127125
nil
128126
end
129127

130-
def params_ordered
131-
@response_object.params_ordered
132-
end
128+
delegate :params_ordered, to: :@response_object
133129

134130
def additional_properties
135131
!!@response_object.additional_properties

lib/apipie/static_dispatcher.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def match?(path)
3030
end
3131
end
3232

33-
def call(env)
34-
@file_server.call(env)
35-
end
33+
delegate :call, to: :@file_server
3634

3735
def ext
3836
@ext ||= begin

lib/apipie/validator.rb

+3-9
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ def description
431431

432432
class DecimalValidator < BaseValidator
433433

434-
def validate(value)
435-
self.class.validate(value)
436-
end
434+
delegate :validate, to: :class
437435

438436
def self.build(param_description, argument, options, block)
439437
if argument == :decimal
@@ -456,9 +454,7 @@ def self.validate(value)
456454

457455
class NumberValidator < BaseValidator
458456

459-
def validate(value)
460-
self.class.validate(value)
461-
end
457+
delegate :validate, to: :class
462458

463459
def self.build(param_description, argument, options, block)
464460
if argument == :number
@@ -549,9 +545,7 @@ def description
549545
"Must be an Array of nested elements"
550546
end
551547

552-
def params_ordered
553-
@validator.params_ordered
554-
end
548+
delegate :params_ordered, to: :@validator
555549
end
556550

557551
end

spec/dummy/config/boot.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
Bundler.setup
88
end
99

10-
require "logger" # Fix concurrent-ruby removing logger dependency which Rails itself does not have
10+
require 'logger' # Fix concurrent-ruby removing logger dependency which Rails itself does not have
1111

1212
$:.unshift File.expand_path('../../../lib', __dir__)

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def fail(msg)
3838

3939
match do |unresolved|
4040
actual = resolve_refs(unresolved)
41-
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if (actual[:type]) != 'object'
41+
return fail("expected schema to have type 'object' (got '#{actual[:type]}')") if actual[:type] != 'object'
4242
return fail("expected schema to include param named '#{name}' (got #{actual[:properties].keys})") if (prop = actual[:properties][name]).nil?
4343
return fail("expected param '#{name}' to have type '#{type}' (got '#{prop[:type]}')") if prop[:type] != type
4444
return fail("expected param '#{name}' to have description '#{opts[:description]}' (got '#{prop[:description]}')") if opts[:description] && prop[:description] != opts[:description]

0 commit comments

Comments
 (0)