Skip to content

Commit b128af8

Browse files
authored
Preparations for 3.0 (#340)
* Preparations for 3.0 - ome maintainance tasks. - updates rubocop and make it happy - updates .travis matrix. - adds CHANGELOG and UPGRADE entries - did not run coveralls for jruby
1 parent b455477 commit b128af8

File tree

8 files changed

+80
-21
lines changed

8 files changed

+80
-21
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ after_success:
99
rvm:
1010
- 2.5.8
1111
- 2.6.6
12-
- 2.7.1
12+
- 2.7.2
1313
- ruby-head
1414
- jruby-head
15+
- truffleruby-head
16+
- 2.4.10
17+
1518

1619
matrix:
1720
fast_finish: true
1821

19-
include:
20-
- rvm: 2.4.10
21-
2222
allow_failures:
2323
- rvm: 2.4.10
2424
- rvm: ruby-head
2525
- rvm: jruby-head
26+
- rvm: truffleruby-head

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#### Fixes
88

9+
* Your contribution here.
10+
* [#340](https://github.com/ruby-grape/grape-entity/pull/340): Preparations for 3.0 - [@LeFnord](https://github.com/LeFnord).
911
* [#338](https://github.com/ruby-grape/grape-entity/pull/338): Fix ruby 2.7 deprecation warning - [@begotten63](https://github.com/begotten63).
1012

1113
### 0.8.1 (2020-07-15)

UPGRADING.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
Upgrading Grape Entity
2-
===============
1+
# Upgrading Grape Entity
2+
3+
### Upgrading to >= 0.8.2
4+
5+
In Ruby 3.0: the block handling will be changed
6+
[language-changes point 3, Proc](https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md#language-changes).
7+
This:
8+
```ruby
9+
expose :that_method_without_args, &:method_without_args
10+
```
11+
will be deprecated.
12+
13+
Prefer to use this pattern for simple setting a value
14+
```ruby
15+
expose :method_without_args, as: :that_method_without_args
16+
```
317

418
### Upgrading to >= 0.6.0
519

lib/grape_entity.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
require 'grape_entity/delegator'
1010
require 'grape_entity/exposure'
1111
require 'grape_entity/options'
12+
require 'grape_entity/deprecated'

lib/grape_entity/deprecated.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
module Grape
4+
class Entity
5+
class Deprecated < StandardError
6+
def initialize(msg, spec)
7+
message = "DEPRECATED #{spec}: #{msg}"
8+
9+
super(message)
10+
end
11+
end
12+
end
13+
end

lib/grape_entity/entity.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ def exec_with_object(options, &block)
525525
else
526526
instance_exec(object, options, &block)
527527
end
528+
rescue StandardError => e
529+
# it handles: https://github.com/ruby/ruby/blob/v3_0_0_preview1/NEWS.md#language-changes point 3, Proc
530+
raise Grape::Entity::Deprecated.new e.message, 'in ruby 3.0' if e.is_a?(ArgumentError)
531+
532+
raise e.class, e.message
528533
end
529534

530535
def exec_with_attribute(attribute, &block)

spec/grape_entity/entity_spec.rb

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,50 @@ class BogusEntity < Grape::Entity
262262
end
263263
end
264264

265-
context 'with block passed via &' do
266-
it 'with does not pass options when block is passed via &' do
267-
class SomeObject
268-
def method_without_args
269-
'result'
270-
end
265+
describe 'blocks' do
266+
class SomeObject
267+
def method_without_args
268+
'result'
271269
end
270+
end
271+
272+
describe 'with block passed in' do
273+
specify do
274+
subject.expose :that_method_without_args do |object|
275+
object.method_without_args
276+
end
277+
278+
object = SomeObject.new
272279

273-
subject.expose :that_method_without_args do |object|
274-
object.method_without_args
280+
value = subject.represent(object).value_for(:that_method_without_args)
281+
expect(value).to eq('result')
275282
end
283+
end
284+
285+
context 'with block passed in via &' do
286+
if RUBY_VERSION.start_with?('3')
287+
specify do
288+
subject.expose :that_method_without_args, &:method_without_args
289+
subject.expose :method_without_args, as: :that_method_without_args_again
276290

277-
subject.expose :that_method_without_args_again, &:method_without_args
291+
object = SomeObject.new
292+
expect do
293+
subject.represent(object).value_for(:that_method_without_args)
294+
end.to raise_error Grape::Entity::Deprecated
278295

279-
object = SomeObject.new
296+
value2 = subject.represent(object).value_for(:that_method_without_args_again)
297+
expect(value2).to eq('result')
298+
end
299+
else
300+
specify do
301+
subject.expose :that_method_without_args_again, &:method_without_args
280302

281-
value = subject.represent(object).value_for(:that_method_without_args)
282-
expect(value).to eq('result')
303+
object = SomeObject.new
283304

284-
value2 = subject.represent(object).value_for(:that_method_without_args_again)
285-
expect(value2).to eq('result')
305+
value2 = subject.represent(object).value_for(:that_method_without_args_again)
306+
expect(value2).to eq('result')
307+
end
308+
end
286309
end
287310
end
288311

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
add_filter 'spec/'
1414
end
1515

16-
Coveralls.wear!
16+
Coveralls.wear! unless RUBY_PLATFORM.eql? 'java'
1717

1818
$LOAD_PATH.unshift(File.dirname(__FILE__))
1919
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

0 commit comments

Comments
 (0)