Skip to content

Commit 1e6aaec

Browse files
author
James McCarthy
committed
Merge branch 'rubocop-cleanup' into dynamic-keys
2 parents 17b0c6c + 2fffb0f commit 1e6aaec

File tree

8 files changed

+68
-40
lines changed

8 files changed

+68
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ dist
3232
Gemfile.lock
3333
tmp
3434
coverage/
35+
.byebug_history
36+
.ruby-version
37+
.ruby-gemset
3538

3639
## Rubinius
3740
.rbx

.rubocop.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
AllCops:
2+
TargetRubyVersion: 2.1
3+
Include:
4+
- Dangerfile
5+
26
Exclude:
37
- vendor/**/*
8+
- bin/**/*
49
- Guardfile
510

611
inherit_from: .rubocop_todo.yml
12+
13+
Style/FileName:
14+
Exclude:
15+
- 'Gemfile'
16+
- 'Rakefile'
17+
- 'grape-entity.gemspec'
18+
- 'lib/grape-entity.rb'
19+
20+
Style/Documentation:
21+
Enabled: false
22+
23+
Style/MultilineIfModifier:
24+
Enabled: false
25+
26+
Style/RaiseArgs:
27+
Enabled: false
28+
29+
Lint/UnneededDisable:
30+
Enabled: false

.rubocop_todo.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-11-20 10:04:42 -0500 using RuboCop version 0.45.0.
3+
# on 2017-04-05 10:30:29 +0700 using RuboCop version 0.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 1
10+
Lint/AmbiguousBlockAssociation:
11+
Exclude:
12+
- 'spec/grape_entity/exposure/represent_exposure_spec.rb'
13+
914
# Offense count: 6
1015
Metrics/AbcSize:
1116
Max: 32
1217

18+
# Offense count: 35
19+
# Configuration parameters: CountComments, ExcludedMethods.
20+
Metrics/BlockLength:
21+
Max: 1499
22+
1323
# Offense count: 2
1424
# Configuration parameters: CountComments.
1525
Metrics/ClassLength:
@@ -19,27 +29,17 @@ Metrics/ClassLength:
1929
Metrics/CyclomaticComplexity:
2030
Max: 11
2131

22-
# Offense count: 237
23-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
32+
# Offense count: 238
33+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
2434
# URISchemes: http, https
2535
Metrics/LineLength:
2636
Max: 146
2737

28-
# Offense count: 6
38+
# Offense count: 7
2939
# Configuration parameters: CountComments.
3040
Metrics/MethodLength:
3141
Max: 28
3242

3343
# Offense count: 2
3444
Metrics/PerceivedComplexity:
3545
Max: 13
36-
37-
# Offense count: 33
38-
Style/Documentation:
39-
Enabled: false
40-
41-
# Offense count: 1
42-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
43-
Style/FileName:
44-
Exclude:
45-
- 'lib/grape-entity.rb'

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Features
44

5+
* [#264](https://github.com/ruby-grape/grape-entity/pull/264): Adds Rubocop config and todo list - [@james2m](https://github.com/james2m).
56
* [#255](https://github.com/ruby-grape/grape-entity/pull/255): Adds code coverage w/ coveralls - [@LeFnord](https://github.com/LeFnord).
67

78
* Your contribution here.

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)