Skip to content

Commit d2d6ba2

Browse files
author
James McCarthy
committed
Autofix some Rubocop errors.
1 parent eb2bc63 commit d2d6ba2

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ RSpec::Core::RakeTask.new(:spec)
1717
require 'rubocop/rake_task'
1818
RuboCop::RakeTask.new(:rubocop)
1919

20-
task default: [:spec, :rubocop]
20+
task default: %i[spec rubocop]

lib/grape_entity/entity.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def to_xml(options = {})
506506
end
507507

508508
# All supported options.
509-
OPTIONS = [
510-
:rewrite, :as, :if, :unless, :using, :with, :proc, :documentation, :format_with, :safe, :attr_path, :if_extras, :unless_extras, :merge
509+
OPTIONS = %i[
510+
rewrite as if unless using with proc documentation format_with safe attr_path if_extras unless_extras merge
511511
].to_set.freeze
512512

513513
# Merges the given options with current block options.
@@ -517,7 +517,7 @@ def self.merge_options(options)
517517
opts = {}
518518

519519
merge_logic = proc do |key, existing_val, new_val|
520-
if [:if, :unless].include?(key)
520+
if %i[if unless].include?(key)
521521
if existing_val.is_a?(Hash) && new_val.is_a?(Hash)
522522
existing_val.merge(new_val)
523523
elsif new_val.is_a?(Hash)

lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def clear
3030
@exposures.clear
3131
end
3232

33-
[
34-
:each,
35-
:to_ary, :to_a,
36-
:all?,
37-
:select,
38-
:each_with_object,
39-
:[],
40-
:==,
41-
:size,
42-
:count,
43-
:length,
44-
:empty?
33+
%i[
34+
each
35+
to_ary to_a
36+
all?
37+
select
38+
each_with_object
39+
\[\]
40+
==
41+
size
42+
count
43+
length
44+
empty?
4545
].each do |name|
4646
class_eval <<-RUBY, __FILE__, __LINE__
4747
def #{name}(*args, &block)

spec/grape_entity/entity_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ class Parent < Person
653653
context 'with specified fields' do
654654
it 'returns only specified fields with only option' do
655655
subject.expose(:id, :name, :phone)
656-
representation = subject.represent(OpenStruct.new, only: [:id, :name], serializable: true)
656+
representation = subject.represent(OpenStruct.new, only: %i[id name], serializable: true)
657657
expect(representation).to eq(id: nil, name: nil)
658658
end
659659

@@ -666,7 +666,7 @@ class Parent < Person
666666
it 'returns only fields specified in the only option and not specified in the except option' do
667667
subject.expose(:id, :name, :phone)
668668
representation = subject.represent(OpenStruct.new,
669-
only: [:name, :phone],
669+
only: %i[name phone],
670670
except: [:phone], serializable: true)
671671
expect(representation).to eq(name: nil)
672672
end
@@ -736,7 +736,7 @@ class Parent < Person
736736
subject.expose(:id, :name, :phone)
737737
subject.expose(:user, using: user_entity)
738738

739-
representation = subject.represent(OpenStruct.new(user: {}), only: [:id, :name, { user: [:name, :email] }], serializable: true)
739+
representation = subject.represent(OpenStruct.new(user: {}), only: [:id, :name, { user: %i[name email] }], serializable: true)
740740
expect(representation).to eq(id: nil, name: nil, user: { name: nil, email: nil })
741741
end
742742

@@ -759,7 +759,7 @@ class Parent < Person
759759
subject.expose(:user, using: user_entity)
760760

761761
representation = subject.represent(OpenStruct.new(user: {}),
762-
only: [:id, :name, :phone, user: [:id, :name, :email]],
762+
only: [:id, :name, :phone, user: %i[id name email]],
763763
except: [:phone, { user: [:id] }], serializable: true)
764764
expect(representation).to eq(id: nil, name: nil, user: { name: nil, email: nil })
765765
end
@@ -771,7 +771,7 @@ class Parent < Person
771771
subject.expose(:name)
772772
end
773773

774-
representation = subject.represent(OpenStruct.new, condition: true, only: [:id, :name], serializable: true)
774+
representation = subject.represent(OpenStruct.new, condition: true, only: %i[id name], serializable: true)
775775
expect(representation).to eq(id: nil, name: nil)
776776
end
777777

@@ -781,7 +781,7 @@ class Parent < Person
781781
subject.expose(:name, :mobile_phone)
782782
end
783783

784-
representation = subject.represent(OpenStruct.new, condition: true, except: [:phone, :mobile_phone], serializable: true)
784+
representation = subject.represent(OpenStruct.new, condition: true, except: %i[phone mobile_phone], serializable: true)
785785
expect(representation).to eq(id: nil, name: nil)
786786
end
787787

@@ -863,7 +863,7 @@ class Parent < Person
863863
subject.expose(:id)
864864
subject.expose(:name, as: :title)
865865

866-
representation = subject.represent(OpenStruct.new, condition: true, only: [:id, :title], serializable: true)
866+
representation = subject.represent(OpenStruct.new, condition: true, only: %i[id title], serializable: true)
867867
expect(representation).to eq(id: nil, title: nil)
868868
end
869869

@@ -890,7 +890,7 @@ class Parent < Person
890890
subject.expose(:nephew, using: nephew_entity)
891891

892892
representation = subject.represent(OpenStruct.new(user: {}),
893-
only: [:id, :name, :user], except: [:nephew], serializable: true)
893+
only: %i[id name user], except: [:nephew], serializable: true)
894894
expect(representation).to eq(id: nil, name: nil, user: { id: nil, name: nil, email: nil })
895895
end
896896
end
@@ -1341,8 +1341,8 @@ class NoPathCharacterEntity < Grape::Entity
13411341
it 'allows to pass different :only and :except params using the same instance' do
13421342
fresh_class.expose :a, :b, :c
13431343
presenter = fresh_class.new(a: 1, b: 2, c: 3)
1344-
expect(presenter.serializable_hash(only: [:a, :b])).to eq(a: 1, b: 2)
1345-
expect(presenter.serializable_hash(only: [:b, :c])).to eq(b: 2, c: 3)
1344+
expect(presenter.serializable_hash(only: %i[a b])).to eq(a: 1, b: 2)
1345+
expect(presenter.serializable_hash(only: %i[b c])).to eq(b: 2, c: 3)
13461346
end
13471347
end
13481348
end

0 commit comments

Comments
 (0)