Skip to content

Commit

Permalink
Carry over disabling warnings to subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherold committed Feb 11, 2017
1 parent aef1b46 commit 9636f68
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
17 changes: 5 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-02-01 08:14:39 -0600 using RuboCop version 0.34.2.
# on 2017-02-10 18:48:03 -0600 using RuboCop version 0.34.2.
# 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
Expand All @@ -18,13 +18,13 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 200
Max: 204

# Offense count: 8
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 239
# Offense count: 242
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 170
Expand All @@ -43,7 +43,7 @@ Style/CaseEquality:
Exclude:
- 'lib/hashie/hash.rb'

# Offense count: 34
# Offense count: 36
# Configuration parameters: Exclude.
Style/Documentation:
Enabled: false
Expand All @@ -57,15 +57,8 @@ Style/DoubleNegation:
- 'lib/hashie/mash.rb'
- 'spec/hashie/extensions/coercion_spec.rb'

# Offense count: 5
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
Style/HashSyntax:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
Style/RegexpLiteral:
Exclude:
- 'Guardfile'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ scheme are considered to be bugs.
### Fixed

* [#402](https://github.com/intridea/hashie/pull/402): Use a Railtie to set Hashie.logger on rails boot - [@matthewrudy](https://github.com/matthewrudy).
* [#406](https://github.com/intridea/hashie/pull/406): Ensure that subclasses that disable warnings propagate that setting to grandchild classes - [@michaelherold](https://github.com/michaelherold).
* Your contribution here.

### Security
Expand Down
9 changes: 9 additions & 0 deletions lib/hashie/mash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def self.disable_warnings?
!!@disable_warnings
end

# Inheritance hook that sets class configuration when inherited.
#
# @api semipublic
# @return [void]
def self.inherited(subclass)
super
subclass.disable_warnings if disable_warnings?
end

def self.load(path, options = {})
@_mashes ||= new

Expand Down
11 changes: 11 additions & 0 deletions spec/hashie/mash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@
it 'cannot disable logging on the base Mash' do
expect { Hashie::Mash.disable_warnings }.to raise_error(Hashie::Mash::CannotDisableMashWarnings)
end

it 'carries over the disable for warnings on grandchild classes' do
child_class = Class.new(Hashie::Mash) do
disable_warnings
end
grandchild_class = Class.new(child_class)

grandchild_class.new('trust' => { 'two' => 2 })

expect(logger_output).to be_blank
end
end

context 'updating' do
Expand Down

0 comments on commit 9636f68

Please sign in to comment.