Skip to content

Commit 59148d2

Browse files
committed
Fix lambda style
1 parent 22bc016 commit 59148d2

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ Style/Documentation:
4141
Style/FileName:
4242
Enabled: false
4343

44-
# Offense count: 16
45-
Style/Lambda:
46-
Enabled: false
47-
4844
# Offense count: 1
4945
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
5046
Style/Next:

spec/grape_entity/entity_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class BogusEntity < Grape::Entity
7070

7171
context 'with parameters passed to the block' do
7272
it 'sets the :proc option in the exposure options' do
73-
block = lambda { |_| true }
73+
block = ->(_) { true }
7474
subject.expose :name, using: 'Awesome', &block
7575
expect(subject.exposures[:name]).to eq(proc: block, using: 'Awesome')
7676
end
@@ -112,8 +112,8 @@ class BogusEntity < Grape::Entity
112112

113113
it 'does not represent nested exposures whose conditions are not met' do
114114
subject.expose :awesome do
115-
subject.expose(:condition_met, if: lambda { |_, _| true }) { |_| 'value' }
116-
subject.expose(:condition_not_met, if: lambda { |_, _| false }) { |_| 'value' }
115+
subject.expose(:condition_met, if: ->(_, _) { true }) { |_| 'value' }
116+
subject.expose(:condition_not_met, if: ->(_, _) { false }) { |_| 'value' }
117117
end
118118

119119
expect(subject.represent({}).send(:value_for, :awesome)).to eq(condition_met: 'value')
@@ -228,7 +228,7 @@ class Parent < Person
228228
end
229229

230230
context 'register formatters' do
231-
let(:date_formatter) { lambda { |date| date.strftime('%m/%d/%Y') } }
231+
let(:date_formatter) { ->(date) { date.strftime('%m/%d/%Y') } }
232232

233233
it 'registers a formatter' do
234234
subject.format_with :timestamp, &date_formatter
@@ -261,7 +261,7 @@ class Parent < Person
261261
it 'formats an exposure with a :format_with lambda that returns a value from the entity instance' do
262262
object = {}
263263

264-
subject.expose(:size, format_with: lambda { |_value| self.object.class.to_s })
264+
subject.expose(:size, format_with: ->(_value) { self.object.class.to_s })
265265
expect(subject.represent(object).send(:value_for, :size)).to eq object.class.to_s
266266
end
267267

@@ -364,7 +364,7 @@ class Parent < Person
364364
end
365365

366366
it 'merges nested :if option' do
367-
match_proc = lambda { |_obj, _opts| true }
367+
match_proc = ->(_obj, _opts) { true }
368368

369369
subject.class_eval do
370370
# Symbol
@@ -389,7 +389,7 @@ class Parent < Person
389389
end
390390

391391
it 'merges nested :unless option' do
392-
match_proc = lambda { |_, _| true }
392+
match_proc = ->(_, _) { true }
393393

394394
subject.class_eval do
395395
# Symbol
@@ -433,10 +433,10 @@ class Parent < Person
433433
end
434434

435435
it 'overrides nested :proc option' do
436-
match_proc = lambda { |_obj, _opts| 'more awesomer' }
436+
match_proc = ->(_obj, _opts) { 'more awesomer' }
437437

438438
subject.class_eval do
439-
with_options(proc: lambda { |_obj, _opts| 'awesome' }) do
439+
with_options(proc: ->(_obj, _opts) { 'awesome' }) do
440440
expose :awesome_thing, proc: match_proc
441441
end
442442
end
@@ -773,8 +773,8 @@ class Parent < Person
773773

774774
it "does not expose attributes that don't exist on the object, even with criteria" do
775775
fresh_class.expose :email
776-
fresh_class.expose :nonexistent_attribute, safe: true, if: lambda { false }
777-
fresh_class.expose :nonexistent_attribute2, safe: true, if: lambda { true }
776+
fresh_class.expose :nonexistent_attribute, safe: true, if: -> { false }
777+
fresh_class.expose :nonexistent_attribute2, safe: true, if: -> { true }
778778

779779
res = fresh_class.new(model).serializable_hash
780780
expect(res).to have_key :email
@@ -799,8 +799,8 @@ class Parent < Person
799799

800800
it 'does not expose attributes that are generated by a block but have not passed criteria' do
801801
fresh_class.expose :nonexistent_attribute,
802-
proc: lambda { |_model, _opts| 'I exist, but it is not yet my time to shine' },
803-
if: lambda { |_model, _opts| false }
802+
proc: ->(_model, _opts) { 'I exist, but it is not yet my time to shine' },
803+
if: ->(_model, _opts) { false }
804804
res = fresh_class.new(model).serializable_hash
805805
expect(res).not_to have_key :nonexistent_attribute
806806
end
@@ -821,8 +821,8 @@ class TestEntity < Grape::Entity
821821

822822
it 'does not expose attributes that are generated by a block but have not passed criteria' do
823823
fresh_class.expose :nonexistent_attribute,
824-
proc: lambda { |_, _| 'I exist, but it is not yet my time to shine' },
825-
if: lambda { |_, _| false }
824+
proc: ->(_, _) { 'I exist, but it is not yet my time to shine' },
825+
if: ->(_, _) { false }
826826
res = fresh_class.new(model).serializable_hash
827827
expect(res).not_to have_key :nonexistent_attribute
828828
end
@@ -901,7 +901,7 @@ def timestamp(date)
901901
date.strftime('%m/%d/%Y')
902902
end
903903

904-
expose :fantasies, format_with: lambda { |f| f.reverse }
904+
expose :fantasies, format_with: ->(f) { f.reverse }
905905
end
906906
end
907907

@@ -1238,7 +1238,7 @@ class UserEntity < Grape::Entity
12381238
end
12391239

12401240
it 'only passes through proc :if exposure if it returns truthy value' do
1241-
exposure_options = { if: lambda { |_, opts| opts[:true] } }
1241+
exposure_options = { if: ->(_, opts) { opts[:true] } }
12421242

12431243
expect(subject.send(:conditions_met?, exposure_options, true: false)).to be false
12441244
expect(subject.send(:conditions_met?, exposure_options, true: true)).to be true
@@ -1256,7 +1256,7 @@ class UserEntity < Grape::Entity
12561256
end
12571257

12581258
it 'only passes through proc :unless exposure if it returns falsy value' do
1259-
exposure_options = { unless: lambda { |_, options| options[:true] == true } }
1259+
exposure_options = { unless: ->(_, opts) { opts[:true] == true } }
12601260

12611261
expect(subject.send(:conditions_met?, exposure_options, true: false)).to be true
12621262
expect(subject.send(:conditions_met?, exposure_options, true: true)).to be false

0 commit comments

Comments
 (0)