summaryrefslogtreecommitdiff
path: root/lib/hashie/mash.rb
diff options
context:
space:
mode:
authorMichael Herold <michael.j.herold@gmail.com>2018-02-03 10:23:14 -0600
committerMichael Herold <michael.j.herold@gmail.com>2018-06-17 11:04:56 -0500
commit5a6ffc7e2df076c266c322ae9272b098b3ab40ed (patch)
tree578b274928ce6ac710922c85d050771f52753736 /lib/hashie/mash.rb
parent8fc10095fc409f4db495713c92c0cf8e31d3bfc1 (diff)
downloadhashie-5a6ffc7e2df076c266c322ae9272b098b3ab40ed.tar.gz
Update Rubocop and address the addressable todos
This is a big step forward in our Rubocop setup. I addressed all of the todos from the current version of Rubocop that made sense to. The only things that remain are metrics and one cop that relies on the line length metric to work. I made some judgment calls on disabling a few cops: 1. The `Layout/IndentHeredoc` cop wants you to either use the squiggly heredoc from Ruby 2.3 or introduce a library. Since we are a low-level library that is used as a transitive dependency, we cannot introduce another library as a dependence, so that option is out. Also, we support Rubies back to 2.0 currently, so using the squiggly heredoc isn't an option. Once we remove support for Rubies older than 2.3, we can switch to the squiggly heredoc cop. 2. The `Naming/FileName` cop was reporting false positives for a few files in the repository, so I disabled it on those files. 3. The `Style/DoubleNegation` cop reports lints on a few cases where we use double negation. Given the very generic nature of Hashie, the double-negation is the easiest, clearest way to express that we want an item to be a Boolean. I disabled the cop because we exist in the gray area where this makes sense.
Diffstat (limited to 'lib/hashie/mash.rb')
-rw-r--r--lib/hashie/mash.rb42
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb
index d995138..bc5873c 100644
--- a/lib/hashie/mash.rb
+++ b/lib/hashie/mash.rb
@@ -61,7 +61,7 @@ module Hashie
include Hashie::Extensions::PrettyInspect
include Hashie::Extensions::RubyVersionCheck
- ALLOWED_SUFFIXES = %w(? ! = _)
+ ALLOWED_SUFFIXES = %w[? ! = _].freeze
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.')
@@ -74,7 +74,7 @@ module Hashie
# @api semipublic
# @return [void]
def self.disable_warnings
- fail CannotDisableMashWarnings if self == Hashie::Mash
+ raise CannotDisableMashWarnings if self == Hashie::Mash
@disable_warnings = true
end
@@ -99,9 +99,9 @@ module Hashie
@_mashes ||= new
return @_mashes[path] if @_mashes.key?(path)
- fail ArgumentError, "The following file doesn't exist: #{path}" unless File.file?(path)
+ raise ArgumentError, "The following file doesn't exist: #{path}" unless File.file?(path)
- parser = options.fetch(:parser) { Hashie::Extensions::Parsers::YamlErbParser }
+ parser = options.fetch(:parser) { Hashie::Extensions::Parsers::YamlErbParser }
@_mashes[path] = new(parser.perform(path)).freeze
end
@@ -114,7 +114,7 @@ module Hashie
end
end
- alias_method :to_s, :inspect
+ alias to_s inspect
# If you pass in an existing hash, it will
# convert it to a Mash including recursively
@@ -125,10 +125,10 @@ module Hashie
default ? super(default) : super(&blk)
end
- class << self; alias_method :[], :new; end
+ class << self; alias [] new; end
- alias_method :regular_reader, :[]
- alias_method :regular_writer, :[]=
+ alias regular_reader []
+ alias regular_writer []=
# Retrieves an attribute set in the Mash. Will convert
# any key passed in to a string before retrieving.
@@ -149,8 +149,8 @@ module Hashie
regular_writer(key, convert ? convert_value(value) : value)
end
- alias_method :[], :custom_reader
- alias_method :[]=, :custom_writer
+ alias [] custom_reader
+ alias []= custom_writer
# This is the bang method reader, it will return a new Mash
# if there isn't a value already assigned to the key requested.
@@ -183,26 +183,26 @@ module Hashie
super(*keys.map { |key| convert_key(key) })
end
- alias_method :regular_dup, :dup
+ alias regular_dup dup
# Duplicates the current mash as a new mash.
def dup
self.class.new(self, default, &default_proc)
end
- alias_method :regular_key?, :key?
+ alias regular_key? key?
def key?(key)
super(convert_key(key))
end
- alias_method :has_key?, :key?
- alias_method :include?, :key?
- alias_method :member?, :key?
+ alias has_key? key?
+ alias include? key?
+ alias member? key?
# Performs a deep_update on a duplicate of the
# current mash.
def deep_merge(other_hash, &blk)
dup.deep_update(other_hash, &blk)
end
- alias_method :merge, :deep_merge
+ alias merge deep_merge
# Recursively merges this mash with the passed
# in hash, merging each hash in the hierarchy.
@@ -213,15 +213,15 @@ module Hashie
custom_reader(key).deep_update(v, &blk)
else
value = convert_value(v, true)
- value = convert_value(blk.call(key, self[k], value), true) if blk && self.key?(k)
+ value = convert_value(yield(key, self[k], value), true) if blk && key?(k)
custom_writer(key, value, false)
end
end
self
end
- alias_method :deep_merge!, :deep_update
- alias_method :update, :deep_update
- alias_method :merge!, :update
+ alias deep_merge! deep_update
+ alias update deep_update
+ alias merge! update
# Assigns a value to a key
def assign_property(name, value)
@@ -263,7 +263,7 @@ module Hashie
method_name.end_with?(*ALLOWED_SUFFIXES) && key?(method_name.chop)
end
- def method_missing(method_name, *args, &blk)
+ def method_missing(method_name, *args, &blk) # rubocop:disable Style/MethodMissing
return self.[](method_name, &blk) if key?(method_name)
name, suffix = method_name_and_suffix(method_name)
case suffix