summaryrefslogtreecommitdiff
path: root/lib/hashie/mash.rb
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2017-02-01 08:03:45 -0600
committerMichael Herold <michael.j.herold@gmail.com>2017-02-04 14:38:00 -0600
commitb2f94a486650587573fea808cf0b1dbb06bc57e5 (patch)
tree5c1c075c9be1523b62c94a3a107b9051bbcd400a /lib/hashie/mash.rb
parent24caf3564e3073c68227590e72bf43e0a604ac68 (diff)
downloadhashie-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/mash.rb')
-rw-r--r--lib/hashie/mash.rb25
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(