Skip to content

Commit 031a710

Browse files
author
Christoph Petschnig
committed
Avoid noise when code runs with Ruby warnings
New versions of RSpec have warnings turned on by default: # This setting enables warnings. It's recommended, but in some cases may # be too noisy due to issues in dependencies. config.warnings = true I believe these warnings are helpful in general to write better code. However, Grape Entity is very noisy. I get more than 10 lines of warnings for one single test where Grape Entity is involved. I hope you agree. Some of my changes could also be solved differently for sure. I am happy to discuss and change those cases. I also turned warnings on in the test suite.
1 parent 5a354d9 commit 031a710

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Metrics/AbcSize:
1313
# Offense count: 2
1414
# Configuration parameters: CountComments.
1515
Metrics/ClassLength:
16-
Max: 206
16+
Max: 208
1717

1818
# Offense count: 3
1919
Metrics/CyclomaticComplexity:

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
#### Features
44

5-
* Your contrbution here.
5+
* Your contribution here.
66

77
#### Fixes
88

9-
* Your contrbution here.
9+
* [#251](https://github.com/ruby-grape/grape-entity/pull/251): Avoid noise when code runs with Ruby warnings - [@cpetschnig](https://github.com/cpetschnig).
10+
* Your contribution here.
1011

1112
### 0.6.0 (2016-11-20)
1213

lib/grape_entity/entity.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def self.present_collection(present_collection = false, collection_name = :items
392392
# @option options :only [Array] all the fields that should be returned
393393
# @option options :except [Array] all the fields that should not be returned
394394
def self.represent(objects, options = {})
395+
@present_collection ||= nil
395396
if objects.respond_to?(:to_ary) && !@present_collection
396397
root_element = root_element(:collection_root)
397398
inner = objects.to_ary.map { |object| new(object, options.reverse_merge(collection: true)).presented }
@@ -409,8 +410,9 @@ def self.represent(objects, options = {})
409410
# This method returns the entity's root or collection root node, or its parent's
410411
# @param root_type: either :collection_root or just :root
411412
def self.root_element(root_type)
412-
if instance_variable_get("@#{root_type}")
413-
instance_variable_get("@#{root_type}")
413+
instance_variable = "@#{root_type}"
414+
if instance_variable_defined?(instance_variable) && instance_variable_get(instance_variable)
415+
instance_variable_get(instance_variable)
414416
elsif superclass.respond_to? :root_element
415417
superclass.root_element(root_type)
416418
end

lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class NestedExposures
77

88
def initialize(exposures)
99
@exposures = exposures
10+
@deep_complex_nesting = nil
1011
end
1112

1213
def find_by(attribute)

0 commit comments

Comments
 (0)