Skip to content

Commit

Permalink
Updates travis matrix ...
Browse files Browse the repository at this point in the history
- changed to some rubocop suggestions
  • Loading branch information
LeFnord committed Mar 14, 2019
1 parent 05d743b commit 1443468
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 79 deletions.
55 changes: 33 additions & 22 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- vendor/**/*
- example/**/*
TargetRubyVersion: 2.4
Include:
- Dangerfile

Layout/EmptyLinesAroundArguments:
Enabled: false

Layout/IndentHash:
EnforcedStyle: consistent

Metrics/AbcSize:
Max: 25

Metrics/BlockLength:
Exclude:
- vendor/**/*
- bin/**/*
- Guardfile
- spec/**/*

inherit_from: .rubocop_todo.yml
Metrics/CyclomaticComplexity:
Max: 10

Gemspec/RequiredRubyVersion:
Enabled: false
Metrics/ClassLength:
Max: 300

Naming/FileName:
Metrics/LineLength:
Max: 120
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'grape-entity.gemspec'
- 'lib/grape-entity.rb'
- spec/**/*

Style/Documentation:
Enabled: false
Metrics/MethodLength:
Max: 26
Exclude:
- spec/**/*

Style/MultilineIfModifier:
Enabled: false
Metrics/PerceivedComplexity:
Max: 11

Style/RaiseArgs:
Naming:
Enabled: false

Lint/BooleanSymbol:
Exclude:
- 'spec/grape_entity/exposure_spec.rb'
Style/Documentation:
Enabled: false

Lint/UnneededDisable:
Style/RegexpLiteral:
Enabled: false
55 changes: 12 additions & 43 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,34 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-03-28 21:26:18 +0200 using RuboCop version 0.54.0.
# on 2019-03-15 00:00:57 +0100 using RuboCop version 0.65.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/AmbiguousBlockAssociation:
# Offense count: 6
Lint/BooleanSymbol:
Exclude:
- 'spec/grape_entity/exposure/represent_exposure_spec.rb'

# Offense count: 5
Metrics/AbcSize:
Max: 25
- 'spec/grape_entity/exposure_spec.rb'

# Offense count: 39
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 1632

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 205

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 26
# Offense count: 4
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 146

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 3
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: io, id, to
Naming/UncommunicativeMethodParamName:
# Configuration parameters: EnforcedStyle.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
Exclude:
- 'spec/grape_entity/entity_spec.rb'

# Offense count: 1
Style/EvalWithLocation:
Exclude:
- 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'spec/grape_entity/entity_spec.rb'

# Offense count: 272
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 146
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ after_success:
- bundle exec danger

rvm:
- 2.3.8
- 2.4.5
- 2.5.3
- 2.6.0
- 2.5.4
- 2.6.2
- ruby-head
- jruby-head

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source 'http://rubygems.org'
gemspec

group :development, :test do
gem 'rubocop', '~> 0.61', require: false
gem 'rubocop', '~> 0.65', require: false
end

group :test do
Expand Down
6 changes: 4 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec', version: 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/support/shared_versioning_examples.rb$}) { |_m| 'spec/' }
watch('spec/spec_helper.rb') { 'spec/' }
watch('spec/spec_helper.rb') { 'spec/' }
end

guard 'bundler' do
Expand Down
2 changes: 1 addition & 1 deletion grape-entity.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.description = 'Extracted from Grape, A Ruby framework for rapid API development with great conventions.'
s.license = 'MIT'

s.required_ruby_version = '>= 2.3'
s.required_ruby_version = '>= 2.4'

s.rubyforge_project = 'grape-entity'

Expand Down
22 changes: 21 additions & 1 deletion lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ def self.inherited(subclass)
# @option options :documentation Define documenation for an exposed
# field, typically the value is a hash with two fields, type and desc.
# @option options :merge This option allows you to merge an exposed field to the root
#
# rubocop:disable Metrics/LineLength
def self.expose(*args, &block)
options = merge_options(args.last.is_a?(Hash) ? args.pop : {})

if args.size > 1

raise ArgumentError, 'You may not use the :as option on multi-attribute exposures.' if options[:as]
raise ArgumentError, 'You may not use the :expose_nil on multi-attribute exposures.' if options.key?(:expose_nil)
raise ArgumentError, 'You may not use block-setting on multi-attribute exposures.' if block_given?
Expand All @@ -191,6 +194,7 @@ def self.expose(*args, &block)
@nesting_stack ||= []
args.each { |attribute| build_exposure_for_attribute(attribute, @nesting_stack, options, block) }
end
# rubocop:enable Metrics/LineLength

def self.build_exposure_for_attribute(attribute, nesting_stack, options, block)
exposure_list = nesting_stack.empty? ? root_exposures : nesting_stack.last.nested_exposures
Expand Down Expand Up @@ -291,6 +295,7 @@ def self.documentation
#
def self.format_with(name, &block)
raise ArgumentError, 'You must pass a block for formatters' unless block_given?

formatters[name.to_sym] = block
end

Expand Down Expand Up @@ -534,7 +539,22 @@ def to_xml(options = {})

# All supported options.
OPTIONS = %i[
rewrite as if unless using with proc documentation format_with safe attr_path if_extras unless_extras merge expose_nil override
rewrite
as
if
unless
using
with
proc
documentation
format_with
safe
attr_path
if_extras
unless_extras
merge
expose_nil
override
].to_set.freeze

# Merges the given options with current block options.
Expand Down
5 changes: 4 additions & 1 deletion lib/grape_entity/exposure/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def valid?(entity)
if @is_safe
is_delegatable
else
is_delegatable || raise(NoMethodError, "#{entity.class.name} missing attribute `#{@attribute}' on #{entity.object}")
is_delegatable || raise(
NoMethodError,
"#{entity.class.name} missing attribute `#{@attribute}' on #{entity.object}"
)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/grape_entity/exposure/nesting_exposure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def normalized_exposures(entity, options)
exposure.should_expose?(entity, options)
end
next unless should_expose

output[exposure.key(entity)] ||= []
output[exposure.key(entity)] << exposure
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def clear
length
empty?
].each do |name|
class_eval <<-RUBY, __FILE__, __LINE__
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{name}(*args, &block)
@exposures.#{name}(*args, &block)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def add(exposure, result)
# If we have an array which should not be merged - save it with a key as a hash
# If we have hash which should be merged - save it without a key (merge)
return unless result

@output_hash.merge! result, &merge_strategy(exposure.for_merge)
else
@output_hash[exposure.key(@entity)] = result
Expand Down
2 changes: 1 addition & 1 deletion spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ class TestEntity < Grape::Entity
expect(res).to have_key :nonexistent_attribute
end

it "exposes attributes defined through module inclusion" do
it 'exposes attributes defined through module inclusion' do
module SharedAttributes
def a_value
3.14
Expand Down
6 changes: 3 additions & 3 deletions spec/grape_entity/exposure/represent_exposure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
let(:subexposure) { double(:subexposure) }

it 'sets using_class_name' do
expect { subject }.to change { exposure.using_class_name }.to(using_class_name)
expect { subject }.to change(exposure, :using_class_name).to(using_class_name)
end

it 'sets subexposure' do
expect { subject }.to change { exposure.subexposure }.to(subexposure)
expect { subject }.to change(exposure, :subexposure).to(subexposure)
end

context 'when using_class is set' do
Expand All @@ -25,7 +25,7 @@
end

it 'resets using_class' do
expect { subject }.to change { exposure.using_class }
expect { subject }.to change(exposure, :using_class)
end
end
end
Expand Down

0 comments on commit 1443468

Please sign in to comment.