diff options
author | Michael Herold <michael.j.herold@gmail.com> | 2017-02-01 08:03:45 -0600 |
---|---|---|
committer | Michael Herold <michael.j.herold@gmail.com> | 2017-02-04 14:38:00 -0600 |
commit | b2f94a486650587573fea808cf0b1dbb06bc57e5 (patch) | |
tree | 5c1c075c9be1523b62c94a3a107b9051bbcd400a /lib/hashie | |
parent | 24caf3564e3073c68227590e72bf43e0a604ac68 (diff) | |
download | hashie-b2f94a486650587573fea808cf0b1dbb06bc57e5.tar.gz |
Allow Mash subclasses to disable warnings
Since we are transitively used as a dependency in many projects, we
should have given the ability to toggle this behavior off. The logging
feature is more of a "help people get started with Mash" feature. If
you're using Hashie in a library, it's likely that you already know the
tradeoffs of attempting to override methods on the object.
To use this feature, you only have to subclass Mash and then call the
class method:
```ruby
class KeyStore < Hashie::Mash
disable_warnings
end
```
Diffstat (limited to 'lib/hashie')
-rw-r--r-- | lib/hashie/mash.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index c84fa92..603b8c5 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -63,6 +63,29 @@ module Hashie ALLOWED_SUFFIXES = %w(? ! = _) + class CannotDisableMashWarnings < StandardError + def initialize(message = 'You cannot disable warnings on the base Mash class. Please subclass the Mash and disable it in the subclass.') + super(message) + end + end + + # Disable the logging of warnings based on keys conflicting keys/methods + # + # @api semipublic + # @return [void] + def self.disable_warnings + fail CannotDisableMashWarnings if self == Hashie::Mash + @disable_warnings = true + end + + # Checks whether this class disables warnings for conflicting keys/methods + # + # @api semipublic + # @return [Boolean] + def self.disable_warnings? + !!@disable_warnings + end + def self.load(path, options = {}) @_mashes ||= new @@ -303,6 +326,8 @@ module Hashie private def log_built_in_message(method_key) + return if self.class.disable_warnings? + method_information = Hashie::Utils.method_information(method(method_key)) Hashie.logger.warn( |