diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d0d957c..b862edf6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -### 1.7.2 (Next) +### 1.8.0 (Next) #### Features +* [#2326](https://github.com/ruby-grape/grape/pull/2326): Use ActiveSupport extensions - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/README.md b/README.md index 8ff988925..a334a72a8 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ content negotiation, versioning and much more. ## Stable Release -You're reading the documentation for the next release of Grape, which should be **1.7.2**. +You're reading the documentation for the next release of Grape, which should be **1.8.0**. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. The current stable release is [1.7.1](https://github.com/ruby-grape/grape/blob/v1.7.1/README.md). diff --git a/grape.gemspec b/grape.gemspec index bee87fbc6..e79e1c0ed 100644 --- a/grape.gemspec +++ b/grape.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| 'source_code_uri' => "https://github.com/ruby-grape/grape/tree/v#{s.version}" } - s.add_runtime_dependency 'activesupport' + s.add_runtime_dependency 'activesupport', '>= 5' s.add_runtime_dependency 'builder' s.add_runtime_dependency 'dry-types', '>= 1.1' s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0' diff --git a/lib/grape.rb b/lib/grape.rb index f51a2e8b0..ed309e16f 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -20,9 +20,11 @@ require 'active_support/core_ext/hash/deep_merge' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/indifferent_access' +require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/object/duplicable' require 'active_support/dependencies/autoload' require 'active_support/notifications' require 'i18n' @@ -92,8 +94,6 @@ module Exceptions module Extensions extend ::ActiveSupport::Autoload eager_autoload do - autoload :DeepMergeableHash - autoload :DeepSymbolizeHash autoload :Hash end module ActiveSupport diff --git a/lib/grape/content_types.rb b/lib/grape/content_types.rb index 2c19f9731..c6f295154 100644 --- a/lib/grape/content_types.rb +++ b/lib/grape/content_types.rb @@ -17,17 +17,11 @@ module ContentTypes class << self def content_types_for_settings(settings) - return if settings.blank? - - settings.each_with_object({}) { |value, result| result.merge!(value) } + settings&.inject(:merge!) end def content_types_for(from_settings) - if from_settings.present? - from_settings - else - Grape::ContentTypes::CONTENT_TYPES.merge(default_elements) - end + from_settings.presence || Grape::ContentTypes::CONTENT_TYPES.merge(default_elements) end end end diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index a54967ead..e2ee006c7 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -103,7 +103,7 @@ def handle_passed_param(params_nested_path, has_passed_children = false, &_block if type == 'Hash' && !has_children {} - elsif type == 'Array' || (type&.start_with?('[') && !type&.include?(',')) + elsif type == 'Array' || (type&.start_with?('[') && type&.exclude?(',')) [] elsif type == 'Set' || type&.start_with?('# value) - end - end end end end diff --git a/lib/grape/validations/validators/base.rb b/lib/grape/validations/validators/base.rb index 2c8403bbc..86813bf9b 100644 --- a/lib/grape/validations/validators/base.rb +++ b/lib/grape/validations/validators/base.rb @@ -71,7 +71,7 @@ def self.convert_to_short_name(klass) end def self.inherited(klass) - return unless klass.name.present? + return if klass.name.blank? Validations.register_validator(convert_to_short_name(klass), klass) end diff --git a/lib/grape/validations/validators/default_validator.rb b/lib/grape/validations/validators/default_validator.rb index 8ed593675..4058d7b1d 100644 --- a/lib/grape/validations/validators/default_validator.rb +++ b/lib/grape/validations/validators/default_validator.rb @@ -12,10 +12,10 @@ def initialize(attrs, options, required, scope, **opts) def validate_param!(attr_name, params) params[attr_name] = if @default.is_a? Proc @default.call - elsif @default.frozen? || !duplicatable?(@default) + elsif @default.frozen? || !@default.duplicable? @default else - duplicate(@default) + @default.dup end end @@ -27,24 +27,6 @@ def validate!(params) validate_param!(attr_name, resource_params) if resource_params.is_a?(Hash) && resource_params[attr_name].nil? end end - - private - - # return true if we might be able to dup this object - def duplicatable?(obj) - !obj.nil? && - obj != true && - obj != false && - !obj.is_a?(Symbol) && - !obj.is_a?(Numeric) - end - - # make a best effort to dup the object - def duplicate(obj) - obj.dup - rescue TypeError - obj - end end end end diff --git a/lib/grape/version.rb b/lib/grape/version.rb index 6b84a9611..64b7c4785 100644 --- a/lib/grape/version.rb +++ b/lib/grape/version.rb @@ -2,5 +2,5 @@ module Grape # The current version of Grape. - VERSION = '1.7.2' + VERSION = '1.8.0' end diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 008a42026..44dc83153 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -3311,7 +3311,7 @@ def static it 'is able to cascade' do subject.mount lambda { |env| headers = {} - headers['X-Cascade'] == 'pass' unless env['PATH_INFO'].include?('boo') + headers['X-Cascade'] == 'pass' if env['PATH_INFO'].exclude?('boo') [200, headers, ['Farfegnugen']] } => '/'