summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorBobby McDonald <BobbyMcWho@users.noreply.github.com>2019-07-18 13:11:41 -0400
committerMichael Herold <opensource@michaeljherold.com>2019-07-18 12:11:40 -0500
commitf0faaca6acc69689aa208c4420c258506a0596af (patch)
tree84e43dde19e0968584c40c80f4d1d210fab53648 /README.md
parentda9fd39a0e551e09c1441cb7453c969a4afbfd7f (diff)
downloadhashie-f0faaca6acc69689aa208c4420c258506a0596af.tar.gz
Add selective key-conflict warnings for Mash subclasses (#478)
In some cases, you want to be able to ignore Mash warnings for keys that you know you aren't going to access via a method accessor, yet be warned for other keys that you know you might want to access. This change adds the ability to selectively ignore warnings for specific keys instead of globally ignoring the warnings. The change retains the original behavior as well, so if you call `Mash.disable_warnings` without a value it will still globally ignore the warnings.
Diffstat (limited to 'README.md')
-rw-r--r--README.md42
1 files changed, 42 insertions, 0 deletions
diff --git a/README.md b/README.md
index ea00cf0..0a088dd 100644
--- a/README.md
+++ b/README.md
@@ -515,6 +515,48 @@ class Response < Hashie::Mash
end
```
+The default is to disable logging for all methods that conflict. If you would like to only disable the logging for specific methods, you can include an array of method keys:
+
+```ruby
+class Response < Hashie::Mash
+ disable_warnings :zip, :zap
+end
+```
+
+This behavior is cumulative. The examples above and below behave identically.
+
+```ruby
+class Response < Hashie::Mash
+ disable_warnings :zip
+ disable_warnings :zap
+end
+```
+
+Disable warnings will honor the last `disable_warnings` call. Calling without parameters will override the blacklist, and calling with parameters will create a new blacklist. This includes child classes that inherit from a class that disables warnings.
+
+```ruby
+class Message < Hashie::Mash
+ disable_warnings :zip, :zap
+ disable_warnings
+end
+
+# No errors will be logged
+Message.new(merge: 'true', compact: true)
+```
+
+```ruby
+class Message < Hashie::Mash
+ disable_warnings
+end
+
+class Response < Message
+ disable_warnings :zip, :zap
+end
+
+# 2 errors will be logged
+Response.new(merge: 'true', compact: true, zip: '90210', zap: 'electric')
+```
+
### How does the wrapping of Mash sub-Hashes work?
Mash duplicates any sub-Hashes that you add to it and wraps them in a Mash. This allows for infinite chaining of nested Hashes within a Mash without modifying the object(s) that are passed into the Mash. When you subclass Mash, the subclass wraps any sub-Hashes in its own class. This preserves any extensions that you mixed into the Mash subclass and allows them to work within the sub-Hashes, in addition to the main containing Mash.