From 8bc30adc0073805ebd698f894a900f760e69d6f9 Mon Sep 17 00:00:00 2001 From: Tim Hogg Date: Wed, 10 May 2017 16:10:00 -0600 Subject: [PATCH] silence warnings initialize vars in initializers subclass hashie mash to silence warnings rubocop fixes add changelog entry Revert "use correct params class in declared" This reverts commit 61f0c8ef9f470b9a2b520437e6635bfc409298cf. fix tests --- .rubocop_todo.yml | 23 ++++++++----------- CHANGELOG.md | 1 + lib/grape/endpoint.rb | 5 ++++ lib/grape/extensions/hashie/mash.rb | 7 ++++-- lib/grape/validations/validators/values.rb | 3 +++ .../param_builders/hashie/mash_spec.rb | 12 +++++----- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1d7f66c286..a53d62fa9e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,51 +1,46 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-02-19 15:40:46 -0500 using RuboCop version 0.47.1. +# on 2017-05-12 09:35:16 -0600 using RuboCop version 0.47.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 43 +# Offense count: 46 Metrics/AbcSize: Max: 44 -# Offense count: 265 +# Offense count: 276 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 3104 -# Offense count: 1 -# Configuration parameters: CountBlocks. -Metrics/BlockNesting: - Max: 4 - # Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 281 + Max: 285 -# Offense count: 26 +# Offense count: 28 Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 993 +# Offense count: 1084 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 215 -# Offense count: 56 +# Offense count: 57 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 33 -# Offense count: 9 +# Offense count: 10 # Configuration parameters: CountComments. Metrics/ModuleLength: Max: 212 -# Offense count: 16 +# Offense count: 18 Metrics/PerceivedComplexity: Max: 14 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dccef1db0..5929929169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ #### Fixes +* [#1632](https://github.com/ruby-grape/grape/pull/1632): Silence warnings - [@thogg4](https://github.com/thogg4). * [#1615](https://github.com/ruby-grape/grape/pull/1615): Fix default and type validator when values is a Hash with no value attribute - [@jlfaber](https://github.com/jlfaber). * Your contribution here. diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index 3ff2d6c380..09250dd847 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -96,6 +96,11 @@ def initialize(new_settings, options = {}, &block) @lazy_initialized = nil @block = nil + @status = nil + @file = nil + @body = nil + @proc = nil + return unless block_given? @source = block diff --git a/lib/grape/extensions/hashie/mash.rb b/lib/grape/extensions/hashie/mash.rb index 50958f3224..b78a2901f0 100644 --- a/lib/grape/extensions/hashie/mash.rb +++ b/lib/grape/extensions/hashie/mash.rb @@ -4,7 +4,6 @@ module Hashie module Mash module ParamBuilder extend ::ActiveSupport::Concern - included do namespace_inheritable(:build_params_with, Grape::Extensions::Hashie::Mash::ParamBuilder) end @@ -14,10 +13,14 @@ def params_builder end def build_params - params = ::Hashie::Mash.new(rack_params) + params = Mash.new(rack_params) params.deep_merge!(grape_routing_args) if env[Grape::Env::GRAPE_ROUTING_ARGS] params end + + class Mash < ::Hashie::Mash + disable_warnings + end end end end diff --git a/lib/grape/validations/validators/values.rb b/lib/grape/validations/validators/values.rb index 2204692252..776dc314ad 100644 --- a/lib/grape/validations/validators/values.rb +++ b/lib/grape/validations/validators/values.rb @@ -14,6 +14,9 @@ def initialize(attrs, options, required, scope, opts = {}) warn '[DEPRECATION] The values validator proc option is deprecated. ' \ 'The lambda expression can now be assigned directly to values.' if @proc else + @excepts = nil + @values = nil + @proc = nil @values = options end super diff --git a/spec/grape/extensions/param_builders/hashie/mash_spec.rb b/spec/grape/extensions/param_builders/hashie/mash_spec.rb index 0a5975f2d5..91adecde2a 100644 --- a/spec/grape/extensions/param_builders/hashie/mash_spec.rb +++ b/spec/grape/extensions/param_builders/hashie/mash_spec.rb @@ -19,10 +19,10 @@ def app end end - it 'should be of type Hashie::Mash' do + it 'should be of type Grape::Extensions::Hashie::Mash::ParamBuilder::Mash' do get '/' expect(last_response.status).to eq(200) - expect(last_response.body).to eq('Hashie::Mash') + expect(last_response.body).to eq('Grape::Extensions::Hashie::Mash::ParamBuilder::Mash') end end end @@ -39,10 +39,10 @@ def app end end - it 'should be Hashie::Mash' do + it 'should be Grape::Extensions::Hashie::Mash::ParamBuilder::Mash' do get '/' expect(last_response.status).to eq(200) - expect(last_response.body).to eq('Hashie::Mash') + expect(last_response.body).to eq('Grape::Extensions::Hashie::Mash::ParamBuilder::Mash') end end @@ -55,10 +55,10 @@ def app end end - it 'should be Hashie::Mash' do + it 'should be Grape::Extensions::Hashie::Mash::ParamBuilder::Mash' do get '/foo' expect(last_response.status).to eq(200) - expect(last_response.body).to eq('Hashie::Mash') + expect(last_response.body).to eq('Grape::Extensions::Hashie::Mash::ParamBuilder::Mash') end end