Skip to content

Commit cf57d25

Browse files
authored
Merge pull request #1949 from nbulaj/add-support-for-ruby-2.7
Add support for Ruby 2.7
2 parents c17d44b + 84320ad commit cf57d25

39 files changed

+81
-75
lines changed

.travis.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ gemfile:
88

99
matrix:
1010
include:
11-
- rvm: 2.6.5
11+
- rvm: 2.7.0
1212
script:
1313
- bundle exec danger
14-
- rvm: 2.6.5
14+
- rvm: 2.7.0
1515
gemfile: Gemfile
16-
- rvm: 2.6.5
16+
- rvm: 2.7.0
1717
gemfile: gemfiles/rack_edge.gemfile
18-
- rvm: 2.6.5
18+
- rvm: 2.7.0
1919
gemfile: gemfiles/rails_edge.gemfile
20-
- rvm: 2.6.5
20+
- rvm: 2.7.0
2121
gemfile: gemfiles/rails_5.gemfile
22-
- rvm: 2.6.5
22+
- rvm: 2.7.0
2323
gemfile: gemfiles/multi_json.gemfile
2424
script:
2525
- bundle exec rake
2626
- bundle exec rspec spec/integration/multi_json
27-
- rvm: 2.6.5
27+
- rvm: 2.7.0
2828
gemfile: gemfiles/multi_xml.gemfile
2929
script:
3030
- bundle exec rake
3131
- bundle exec rspec spec/integration/multi_xml
32+
- rvm: 2.6.5
33+
gemfile: Gemfile
34+
- rvm: 2.6.5
35+
gemfile: gemfiles/rails_5.gemfile
3236
- rvm: 2.5.7
3337
gemfile: Gemfile
3438
- rvm: 2.5.7

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#1948](https://github.com/ruby-grape/grape/pull/1949): Add support for Ruby 2.7 - [@nbulaj](https://github.com/nbulaj).
67
* [#1948](https://github.com/ruby-grape/grape/pull/1948): Relax `dry-types` dependency version - [@nbulaj](https://github.com/nbulaj).
78
* [#1944](https://github.com/ruby-grape/grape/pull/1944): Reduces `attribute_translator` string allocations - [@ericproulx](https://github.com/ericproulx).
89
* [#1943](https://github.com/ruby-grape/grape/pull/1943): Reduces number of regex string allocations - [@ericproulx](https://github.com/ericproulx).

lib/grape/api/instance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def add_head_not_allowed_methods_and_options_methods
234234
end
235235

236236
attributes = config.merge(allowed_methods: allowed_methods, allow_header: allow_header)
237-
generate_not_allowed_method(config[:pattern], attributes)
237+
generate_not_allowed_method(config[:pattern], **attributes)
238238
end
239239
end
240240
end

lib/grape/dsl/inside_route.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def self.post_filter_methods(type)
3030
module PostBeforeFilter
3131
def declared(passed_params, options = {}, declared_params = nil)
3232
options = options.reverse_merge(include_missing: true, include_parent_namespaces: true)
33-
declared_params ||= optioned_declared_params(options)
33+
declared_params ||= optioned_declared_params(**options)
3434

3535
if passed_params.is_a?(Array)
3636
declared_array(passed_params, options, declared_params)
@@ -98,7 +98,7 @@ def optioned_param_key(declared_param, options)
9898
options[:stringify] ? declared_param.to_s : declared_param.to_sym
9999
end
100100

101-
def optioned_declared_params(options)
101+
def optioned_declared_params(**options)
102102
declared_params = if options[:include_parent_namespaces]
103103
# Declared params including parent namespaces
104104
route_setting(:saved_declared_params).flatten | Array(route_setting(:declared_params))
@@ -387,7 +387,7 @@ def entity_class_for_obj(object, options)
387387
def entity_representation_for(entity_class, object, options)
388388
embeds = { env: env }
389389
embeds[:version] = env[Grape::Env::API_VERSION] if env[Grape::Env::API_VERSION]
390-
entity_class.represent(object, embeds.merge(options))
390+
entity_class.represent(object, **embeds.merge(options))
391391
end
392392
end
393393
end

lib/grape/dsl/parameters.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def requires(*attrs, &block)
133133
require_required_and_optional_fields(attrs.first, opts)
134134
else
135135
validate_attributes(attrs, opts, &block)
136-
block_given? ? new_scope(orig_attrs, &block) : push_declared_params(attrs, opts.slice(:as))
136+
block_given? ? new_scope(orig_attrs, &block) : push_declared_params(attrs, **opts.slice(:as))
137137
end
138138
end
139139

@@ -159,7 +159,7 @@ def optional(*attrs, &block)
159159
else
160160
validate_attributes(attrs, opts, &block)
161161

162-
block_given? ? new_scope(orig_attrs, true, &block) : push_declared_params(attrs, opts.slice(:as))
162+
block_given? ? new_scope(orig_attrs, true, &block) : push_declared_params(attrs, **opts.slice(:as))
163163
end
164164
end
165165

lib/grape/dsl/request_response.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def format(new_format = nil)
2222
if new_format
2323
namespace_inheritable(:format, new_format.to_sym)
2424
# define the default error formatters
25-
namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, {}))
25+
namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, **{}))
2626
# define a single mime type
2727
mime_type = content_types[new_format.to_sym]
2828
raise Grape::Exceptions::MissingMimeType.new(new_format) unless mime_type
@@ -45,7 +45,7 @@ def parser(content_type, new_parser)
4545
# Specify a default error formatter.
4646
def default_error_formatter(new_formatter_name = nil)
4747
if new_formatter_name
48-
new_formatter = Grape::ErrorFormatter.formatter_for(new_formatter_name, {})
48+
new_formatter = Grape::ErrorFormatter.formatter_for(new_formatter_name, **{})
4949
namespace_inheritable(:default_error_formatter, new_formatter)
5050
else
5151
namespace_inheritable(:default_error_formatter)

lib/grape/dsl/routing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def namespace(space = nil, options = {}, &block)
169169
@namespace_description = (@namespace_description || {}).deep_merge(namespace_setting(:description) || {})
170170
nest(block) do
171171
if space
172-
namespace_stackable(:namespace, Namespace.new(space, options))
172+
namespace_stackable(:namespace, Namespace.new(space, **options))
173173
end
174174
end
175175
@namespace_description = previous_namespace_description

lib/grape/endpoint.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def mount_in(router)
157157
end
158158
methods.each do |method|
159159
unless route.request_method == method
160-
route = Grape::Router::Route.new(method, route.origin, route.attributes.to_h)
160+
route = Grape::Router::Route.new(method, route.origin, **route.attributes.to_h)
161161
end
162162
router.append(route.apply(self))
163163
end
@@ -169,8 +169,8 @@ def to_routes
169169
route_options = prepare_default_route_attributes
170170
map_routes do |method, path|
171171
path = prepare_path(path)
172-
params = merge_route_options(route_options.merge(suffix: path.suffix))
173-
route = Router::Route.new(method, path.path, params)
172+
params = merge_route_options(**route_options.merge(suffix: path.suffix))
173+
route = Router::Route.new(method, path.path, **params)
174174
route.apply(self)
175175
end.flatten
176176
end
@@ -359,7 +359,7 @@ def lazy_initialize!
359359
def run_validators(validator_factories, request)
360360
validation_errors = []
361361

362-
validators = validator_factories.map { |options| Grape::Validations::ValidatorFactory.create_validator(options) }
362+
validators = validator_factories.map { |options| Grape::Validations::ValidatorFactory.create_validator(**options) }
363363

364364
ActiveSupport::Notifications.instrument('endpoint_run_validators.grape', endpoint: self, validators: validators, request: request) do
365365
validators.each do |validator|
@@ -375,7 +375,7 @@ def run_validators(validator_factories, request)
375375
end
376376
end
377377

378-
validation_errors.any? && raise(Grape::Exceptions::ValidationErrors, errors: validation_errors, headers: header)
378+
validation_errors.any? && raise(Grape::Exceptions::ValidationErrors.new(errors: validation_errors, headers: header))
379379
end
380380

381381
def run_filters(filters, type = :other)

lib/grape/error_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def builtin_formatters
1515
}
1616
end
1717

18-
def formatters(options)
18+
def formatters(**options)
1919
builtin_formatters.merge(default_elements).merge!(options[:error_formatters] || {})
2020
end
2121

lib/grape/exceptions/base.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ def compose_message(key, **attributes)
3939
end
4040
end
4141

42-
def problem(key, attributes)
43-
translate_message("#{key}.problem".to_sym, attributes)
42+
def problem(key, **attributes)
43+
translate_message("#{key}.problem".to_sym, **attributes)
4444
end
4545

46-
def summary(key, attributes)
47-
translate_message("#{key}.summary".to_sym, attributes)
46+
def summary(key, **attributes)
47+
translate_message("#{key}.summary".to_sym, **attributes)
4848
end
4949

50-
def resolution(key, attributes)
51-
translate_message("#{key}.resolution".to_sym, attributes)
50+
def resolution(key, **attributes)
51+
translate_message("#{key}.resolution".to_sym, **attributes)
5252
end
5353

5454
def translate_attributes(keys, **options)

0 commit comments

Comments
 (0)