Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/edge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', ruby-head, truffleruby-head, jruby-head]
ruby: ['3.0', '3.1', '3.2', '3.3', '3.4', ruby-head, truffleruby-head, jruby-head]
gemfile: [rails_edge, rack_edge]
exclude:
- ruby: '2.7'
gemfile: rails_edge
- ruby: '3.0'
gemfile: rails_edge
runs-on: ubuntu-latest
Expand Down
20 changes: 2 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
gemfile: [Gemfile, gemfiles/rack_2_0.gemfile, gemfiles/rack_3_0.gemfile, gemfiles/rack_3_1.gemfile, gemfiles/rails_6_1.gemfile, gemfiles/rails_7_0.gemfile, gemfiles/rails_7_1.gemfile, gemfiles/rails_7_2.gemfile, gemfiles/rails_8_0.gemfile]
ruby: ['3.0', '3.1', '3.2', '3.3', '3.4']
gemfile: [Gemfile, gemfiles/rack_2_0.gemfile, gemfiles/rack_3_0.gemfile, gemfiles/rack_3_1.gemfile, gemfiles/rails_7_0.gemfile, gemfiles/rails_7_1.gemfile, gemfiles/rails_7_2.gemfile, gemfiles/rails_8_0.gemfile]
specs: ['spec --exclude-pattern=spec/integration/**/*_spec.rb']
include:
- ruby: '2.7'
gemfile: gemfiles/multi_json.gemfile
specs: 'spec/integration/multi_json'
- ruby: '2.7'
gemfile: gemfiles/multi_xml.gemfile
specs: 'spec/integration/multi_xml'
- ruby: '2.7'
gemfile: gemfiles/rack_3_0.gemfile
specs: 'spec/integration/rack_3_0'
- ruby: '3.3'
gemfile: gemfiles/grape_entity.gemfile
specs: 'spec/integration/grape_entity'
Expand All @@ -45,9 +36,6 @@ jobs:
- ruby: '3.3'
gemfile: gemfiles/dry_validation.gemfile
specs: 'spec/integration/dry_validation'
- ruby: '3.3'
gemfile: gemfiles/rails_6_1.gemfile
specs: 'spec/integration/rails'
- ruby: '3.3'
gemfile: gemfiles/rails_7_0.gemfile
specs: 'spec/integration/rails'
Expand All @@ -61,12 +49,8 @@ jobs:
gemfile: gemfiles/rails_8_0.gemfile
specs: 'spec/integration/rails'
exclude:
- ruby: '2.7'
gemfile: gemfiles/rails_7_2.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_7_2.gemfile
- ruby: '2.7'
gemfile: gemfiles/rails_8_0.gemfile
- ruby: '3.0'
gemfile: gemfiles/rails_8_0.gemfile
- ruby: '3.1'
Expand Down
6 changes: 2 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
AllCops:
NewCops: enable
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
SuggestExtensions: false
Exclude:
- vendor/**/*
- bin/**/*

require:
- rubocop-rspec

plugins:
- rubocop-performance
- rubocop-rspec

inherit_from: .rubocop_todo.yml

Expand Down
13 changes: 6 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-02-23 19:41:28 UTC using RuboCop version 1.71.2.
# on 2025-06-18 20:27:19 UTC using RuboCop version 1.76.2.
# 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
Expand All @@ -15,7 +15,7 @@ Metrics/MethodLength:
# Offense count: 18
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'spec/grape/dsl/settings_spec.rb'
Expand All @@ -39,7 +39,7 @@ RSpec/ExampleWording:
- 'spec/grape/integration/global_namespace_function_spec.rb'
- 'spec/grape/validations_spec.rb'

# Offense count: 7
# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
RSpec/ExpectActual:
Exclude:
Expand All @@ -60,7 +60,7 @@ RSpec/IndexedLet:
- 'spec/grape/presenters/presenter_spec.rb'
- 'spec/shared/versioning_examples.rb'

# Offense count: 39
# Offense count: 40
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
Expand All @@ -75,7 +75,7 @@ RSpec/MessageChain:
Exclude:
- 'spec/grape/middleware/formatter_spec.rb'

# Offense count: 12
# Offense count: 10
RSpec/MissingExampleGroupArgument:
Exclude:
- 'spec/grape/middleware/exception_spec.rb'
Expand Down Expand Up @@ -149,12 +149,11 @@ Style/CombinableLoops:
Exclude:
- 'spec/grape/endpoint_spec.rb'

# Offense count: 12
# Offense count: 11
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/grape/api.rb'
- 'lib/grape/dsl/inside_route.rb'
- 'lib/grape/dsl/parameters.rb'
- 'lib/grape/endpoint.rb'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Features

* [#2572](https://github.com/ruby-grape/grape/pull/2572): Drop support ruby 2.7 and active_support 6.1 - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
10 changes: 1 addition & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Here are some examples:
- running rspec on a specific file `docker-compose run --rm --build grape rspec spec/:file_path`
- running task `docker-compose run --rm --build grape rake <task_name>`
- running rubocop `docker-compose run --rm --build grape rubocop`
- running all specs on a specific ruby version (e.g 2.7.7) `RUBY_VERSION=2.7.7 docker-compose run --rm --build grape rspec`
- running all specs on a specific ruby version (e.g 3.0) `RUBY_VERSION=3.0 docker-compose run --rm --build grape rspec`
- running specs on a specific gemfile (e.g rails_7_0.gemfile) `docker-compose run -e GEMFILE=rails_7_0 --rm --build grape rspec`

#### Bundle Install and Test
Expand All @@ -60,14 +60,6 @@ bundle install
bundle exec rake
```

Run tests against all supported versions of Rails.

```
gem install appraisal
appraisal install
appraisal rake spec
```

#### Write Tests

Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/grape](spec/grape).
Expand Down
6 changes: 2 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# when changing this file, run appraisal install ; rubocop -a gemfiles/*.gemfile

source('https://rubygems.org')

gemspec
Expand All @@ -10,9 +8,9 @@ group :development, :test do
gem 'builder', require: false
gem 'bundler'
gem 'rake'
gem 'rubocop', '1.75.8', require: false
gem 'rubocop', '1.76.2', require: false
gem 'rubocop-performance', '1.25.0', require: false
gem 'rubocop-rspec', '3.4.0', require: false
gem 'rubocop-rspec', '3.6.0', require: false
end

group :development do
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ The maintainers of Grape are working with Tidelift to deliver commercial support

## Installation

Ruby 2.7 or newer is required.
Ruby 3.0 or newer is required.

Grape is available as a gem, to install it run:

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Supported Versions

Version 1.2.0 or newer is currently supported.
Version 2.2 or newer is currently supported.

## Reporting a Vulnerability

Expand Down
7 changes: 0 additions & 7 deletions gemfiles/rails_6_1.gemfile

This file was deleted.

4 changes: 2 additions & 2 deletions grape.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Gem::Specification.new do |s|
'rubygems_mfa_required' => 'true'
}

s.add_dependency 'activesupport', '>= 6.1'
s.add_dependency 'activesupport', '>= 7.0'
s.add_dependency 'dry-types', '>= 1.1'
s.add_dependency 'mustermann-grape', '~> 1.1.0'
s.add_dependency 'rack', '>= 2'
s.add_dependency 'zeitwerk'

s.files = Dir['lib/**/*', 'CHANGELOG.md', 'CONTRIBUTING.md', 'README.md', 'grape.png', 'UPGRADING.md', 'LICENSE', 'grape.gemspec']
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.7.0'
s.required_ruby_version = '>= 3.0'
end
2 changes: 1 addition & 1 deletion lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'active_support/concern'
require 'active_support/configurable'
require 'active_support/version'
require 'active_support/isolated_execution_state' if ActiveSupport::VERSION::MAJOR > 6
require 'active_support/isolated_execution_state'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/wrap'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/request_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module ClassMethods
# Specify the default format for the API's serializers.
# May be `:json` or `:txt` (default).
def default_format(new_format = nil)
namespace_inheritable(:default_format, new_format.nil? ? nil : new_format.to_sym)
namespace_inheritable(:default_format, new_format&.to_sym)
end

# Specify the format for the API's serializers.
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def format_from_extension
dot_pos = request_path.rindex('.')
return unless dot_pos

extension = request_path[dot_pos + 1..]
extension = request_path[(dot_pos + 1)..]
extension if content_type_for(extension)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/grape/middleware/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def insert(index, klass, *args, &block)

alias insert_before insert

def insert_after(index, *args, &block)
def insert_after(index, ...)
index = assert_index(index, :after)
insert(index + 1, *args, &block)
insert(index + 1, ...)
end

def use(klass, *args, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/versioner/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Middleware
module Versioner
class Base < Grape::Middleware::Base
DEFAULT_OPTIONS = {
pattern: /.*/i.freeze,
pattern: /.*/i,
version_options: {
strict: false,
cascade: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/versioner/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def before
slash_position = path_info.index('/', 1) # omit the first one
return unless slash_position

potential_version = path_info[1..slash_position - 1]
potential_version = path_info[1..(slash_position - 1)]
return unless potential_version.match?(pattern)

version_not_found! unless potential_version_match?(potential_version)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.normalize_path(path)

# Slow path
encoding = path.encoding
path = +"/#{path}"
path = "/#{path}"
path.squeeze!('/')

unless path == '/'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/util/media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MediaType

# based on the HTTP Accept header with the pattern:
# application/vnd.:vendor-:version+:format
VENDOR_VERSION_HEADER_REGEX = /\Avnd\.(?<vendor>[a-z0-9.\-_!^]+?)(?:-(?<version>[a-z0-9*.]+))?(?:\+(?<format>[a-z0-9*\-.]+))?\z/.freeze
VENDOR_VERSION_HEADER_REGEX = /\Avnd\.(?<vendor>[a-z0-9.\-_!^]+?)(?:-(?<version>[a-z0-9*.]+))?(?:\+(?<format>[a-z0-9*\-.]+))?\z/

def initialize(type:, subtype:)
@type = type
Expand Down
6 changes: 3 additions & 3 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ def to_txt

it 'adds a before filter to current and child namespaces only' do
subject.get '/' do
"root - #{instance_variable_defined?(:@foo) ? @foo : nil}"
"root - #{@foo if instance_variable_defined?(:@foo)}"
end
subject.namespace :blah do
before { @foo = 'foo' }
Expand Down Expand Up @@ -1676,13 +1676,13 @@ def call(env)

it 'has access to helper methods' do
subject.helpers do
def authorize(user, password)
def authorize?(user, password)
user == 'allow' && password == 'whatever'
end
end

subject.http_basic do |u, p|
authorize(u, p)
authorize?(u, p)
end

subject.get(:hello) { 'Hello, world.' }
Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
Grape.deprecator.behavior = :raise

%w[config support].each do |dir|
Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].sort.each do |file|
Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].each do |file|
require file
end
end

Grape.config.lint = true # lint all apis by default
Grape::Util::Registry.include(Deregister)
# issue with ruby 2.7 with ^. We need to extend it again
Grape::Validations.extend(Grape::Util::Registry) if Gem::Version.new(RUBY_VERSION).release < Gem::Version.new('3.0')

# The default value for this setting is true in a standard Rails app,
# so it should be set to true here as well to reflect that.
Expand Down
2 changes: 1 addition & 1 deletion spec/support/chunked_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ChunkedResponse
class Body
TERM = "\r\n"
TAIL = "0#{TERM}"
TAIL = "0#{TERM}".freeze

# Store the response body to be chunked.
def initialize(body)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/deprecated_warning_handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module DeprecatedWarningHandler
class DeprecationWarning < StandardError; end

DEPRECATION_REGEX = /is deprecated/.freeze
DEPRECATION_REGEX = /is deprecated/

def warn(message)
return super unless message.match?(DEPRECATION_REGEX)
Expand Down