summaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/hashie/clash.rb13
-rw-r--r--lib/hashie/dash.rb27
-rw-r--r--lib/hashie/extensions/coercion.rb10
-rw-r--r--lib/hashie/extensions/dash/property_translation.rb20
-rw-r--r--lib/hashie/extensions/deep_fetch.rb2
-rw-r--r--lib/hashie/extensions/deep_find.rb4
-rw-r--r--lib/hashie/extensions/deep_locate.rb9
-rw-r--r--lib/hashie/extensions/deep_merge.rb17
-rw-r--r--lib/hashie/extensions/indifferent_access.rb6
-rw-r--r--lib/hashie/extensions/mash/keep_original_keys.rb8
-rw-r--r--lib/hashie/extensions/mash/safe_assignment.rb2
-rw-r--r--lib/hashie/extensions/mash/symbolize_keys.rb2
-rw-r--r--lib/hashie/extensions/method_access.rb10
-rw-r--r--lib/hashie/extensions/parsers/yaml_erb_parser.rb2
-rw-r--r--lib/hashie/extensions/strict_key_access.rb17
-rw-r--r--lib/hashie/extensions/stringify_keys.rb2
-rw-r--r--lib/hashie/extensions/symbolize_keys.rb2
-rw-r--r--lib/hashie/hash.rb8
-rw-r--r--lib/hashie/mash.rb42
-rw-r--r--lib/hashie/rash.rb10
-rw-r--r--lib/hashie/version.rb2
21 files changed, 108 insertions, 107 deletions
diff --git a/lib/hashie/clash.rb b/lib/hashie/clash.rb
index 945c146..92dcab4 100644
--- a/lib/hashie/clash.rb
+++ b/lib/hashie/clash.rb
@@ -75,7 +75,7 @@ module Hashie
when Hash
self[key] = self.class.new(self[key], self)
else
- fail ChainError, 'Tried to chain into a non-hash key.'
+ raise ChainError, 'Tried to chain into a non-hash key.'
end
elsif args.any?
merge_store(name, *args)
@@ -83,5 +83,16 @@ module Hashie
super
end
end
+
+ def respond_to_missing?(method_name, _include_private = false)
+ method_name = method_name.to_s
+
+ if method_name.end_with?('!')
+ key = method_name[0...-1].to_sym
+ [NilClass, Clash, Hash].include?(self[key].class)
+ else
+ true
+ end
+ end
end
end
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb
index a111e4b..ee27b11 100644
--- a/lib/hashie/dash.rb
+++ b/lib/hashie/dash.rb
@@ -15,7 +15,7 @@ module Hashie
class Dash < Hash
include Hashie::Extensions::PrettyInspect
- alias_method :to_s, :inspect
+ alias to_s inspect
# Defines a property on the Dash. Options are
# as follows:
@@ -48,16 +48,14 @@ module Hashie
define_method(property_assignment) { |value| self.[]=(property_name, value) }
end
- if defined? @subclasses
- @subclasses.each { |klass| klass.property(property_name, options) }
- end
+ @subclasses.each { |klass| klass.property(property_name, options) } if defined? @subclasses
condition = options.delete(:required)
if condition
message = options.delete(:message) || "is required for #{name}."
required_properties[property_name] = { condition: condition, message: message }
- else
- fail ArgumentError, 'The :message option should be used with :required option.' if options.key?(:message)
+ elsif options.key?(:message)
+ raise ArgumentError, 'The :message option should be used with :required option.'
end
end
@@ -111,8 +109,8 @@ module Hashie
assert_required_attributes_set!
end
- alias_method :_regular_reader, :[]
- alias_method :_regular_writer, :[]=
+ alias _regular_reader []
+ alias _regular_writer []=
private :_regular_reader, :_regular_writer
# Retrieve a value from the Dash (will return the
@@ -163,11 +161,12 @@ module Hashie
update_attributes(attributes)
self.class.defaults.each_pair do |prop, value|
+ next unless self[prop].nil?
self[prop] = begin
value.dup
rescue TypeError
value
- end if self[prop].nil?
+ end
end
assert_required_attributes_set!
end
@@ -208,11 +207,11 @@ module Hashie
end
def fail_property_required_error!(property)
- fail ArgumentError, "The property '#{property}' #{self.class.required_properties[property][:message]}"
+ raise ArgumentError, "The property '#{property}' #{self.class.required_properties[property][:message]}"
end
def fail_no_property_error!(property)
- fail NoMethodError, "The property '#{property}' is not defined for #{self.class.name}."
+ raise NoMethodError, "The property '#{property}' is not defined for #{self.class.name}."
end
def required?(property)
@@ -220,9 +219,9 @@ module Hashie
condition = self.class.required_properties[property][:condition]
case condition
- when Proc then !!(instance_exec(&condition))
- when Symbol then !!(send(condition))
- else !!(condition)
+ when Proc then !!instance_exec(&condition)
+ when Symbol then !!send(condition)
+ else !!condition
end
end
end
diff --git a/lib/hashie/extensions/coercion.rb b/lib/hashie/extensions/coercion.rb
index eb0a6dd..704343e 100644
--- a/lib/hashie/extensions/coercion.rb
+++ b/lib/hashie/extensions/coercion.rb
@@ -10,14 +10,14 @@ module Hashie
Rational => :to_r,
String => :to_s,
Symbol => :to_sym
- }
+ }.freeze
ABSTRACT_CORE_TYPES = if RubyVersion.new(RUBY_VERSION) >= RubyVersion.new('2.4.0')
{ Numeric => [Integer, Float, Complex, Rational] }
else
{
- Integer => [Fixnum, Bignum],
- Numeric => [Fixnum, Bignum, Float, Complex, Rational]
+ Integer => [Fixnum, Bignum], # rubocop:disable Lint/UnifiedInteger
+ Numeric => [Fixnum, Bignum, Float, Complex, Rational] # rubocop:disable Lint/UnifiedInteger
}
end
@@ -78,7 +78,7 @@ module Hashie
attrs.each { |key| key_coercions[key] = into }
end
- alias_method :coerce_keys, :coerce_key
+ alias coerce_keys coerce_key
# Returns a hash of any existing key coercions.
def key_coercions
@@ -180,7 +180,7 @@ module Hashie
type.new(value)
end
else
- fail TypeError, "#{type} is not a coercable type"
+ raise TypeError, "#{type} is not a coercable type"
end
end
diff --git a/lib/hashie/extensions/dash/property_translation.rb b/lib/hashie/extensions/dash/property_translation.rb
index be858b7..2d28080 100644
--- a/lib/hashie/extensions/dash/property_translation.rb
+++ b/lib/hashie/extensions/dash/property_translation.rb
@@ -74,7 +74,7 @@ module Hashie
if options[:from]
if property_name == options[:from]
- fail ArgumentError, "Property name (#{property_name}) and :from option must not be the same"
+ raise ArgumentError, "Property name (#{property_name}) and :from option must not be the same"
end
translations_hash[options[:from]] ||= {}
@@ -85,10 +85,8 @@ module Hashie
self[name] = with.respond_to?(:call) ? with.call(val) : val
end
end
- else
- if options[:transform_with].respond_to? :call
- transforms[property_name] = options[:transform_with]
- end
+ elsif options[:transform_with].respond_to? :call
+ transforms[property_name] = options[:transform_with]
end
end
@@ -107,11 +105,11 @@ module Hashie
def translations
@translations ||= {}.tap do |h|
translations_hash.each do |(property_name, property_translations)|
- if property_translations.size > 1
- h[property_name] = property_translations.keys
- else
- h[property_name] = property_translations.keys.first
- end
+ h[property_name] = if property_translations.size > 1
+ property_translations.keys
+ else
+ property_translations.keys.first
+ end
end
end
end
@@ -119,7 +117,7 @@ module Hashie
def inverse_translations
@inverse_translations ||= {}.tap do |h|
translations_hash.each do |(property_name, property_translations)|
- property_translations.keys.each do |k|
+ property_translations.each_key do |k|
h[k] = property_name
end
end
diff --git a/lib/hashie/extensions/deep_fetch.rb b/lib/hashie/extensions/deep_fetch.rb
index 9149f0d..6ed34f3 100644
--- a/lib/hashie/extensions/deep_fetch.rb
+++ b/lib/hashie/extensions/deep_fetch.rb
@@ -19,7 +19,7 @@ module Hashie
arg = Integer(arg) if obj.is_a? Array
obj.fetch(arg)
rescue ArgumentError, IndexError, NoMethodError => e
- break block.call(arg) if block
+ break yield(arg) if block
raise UndefinedPathError, "Could not fetch path (#{args.join(' > ')}) at #{arg}", e.backtrace
end
end
diff --git a/lib/hashie/extensions/deep_find.rb b/lib/hashie/extensions/deep_find.rb
index 616e659..c4a7646 100644
--- a/lib/hashie/extensions/deep_find.rb
+++ b/lib/hashie/extensions/deep_find.rb
@@ -19,7 +19,7 @@ module Hashie
_deep_find(key)
end
- alias_method :deep_detect, :deep_find
+ alias deep_detect deep_find
# Performs a depth-first search on deeply nested data structures for
# a key and returns all occurrences of the key.
@@ -40,7 +40,7 @@ module Hashie
matches.empty? ? nil : matches
end
- alias_method :deep_select, :deep_find_all
+ alias deep_select deep_find_all
private
diff --git a/lib/hashie/extensions/deep_locate.rb b/lib/hashie/extensions/deep_locate.rb
index 930513a..3577e93 100644
--- a/lib/hashie/extensions/deep_locate.rb
+++ b/lib/hashie/extensions/deep_locate.rb
@@ -61,8 +61,6 @@ module Hashie
Hashie::Extensions::DeepLocate.deep_locate(comparator, self)
end
- private
-
def self._construct_key_comparator(search_key, object)
search_key = search_key.to_s if defined?(::ActiveSupport::HashWithIndifferentAccess) && object.is_a?(::ActiveSupport::HashWithIndifferentAccess)
search_key = search_key.to_s if object.respond_to?(:indifferent_access?) && object.indifferent_access?
@@ -71,12 +69,11 @@ module Hashie
->(key, _, _) { key == non_callable_object }
end.call(search_key)
end
+ private_class_method :_construct_key_comparator
def self._deep_locate(comparator, object, result = [])
if object.is_a?(::Enumerable)
- if object.any? { |value| _match_comparator?(value, comparator, object) }
- result.push object
- end
+ result.push object if object.any? { |value| _match_comparator?(value, comparator, object) }
(object.respond_to?(:values) ? object.values : object.entries).each do |value|
_deep_locate(comparator, value, result)
end
@@ -84,6 +81,7 @@ module Hashie
result
end
+ private_class_method :_deep_locate
def self._match_comparator?(value, comparator, object)
if object.is_a?(::Hash)
@@ -94,6 +92,7 @@ module Hashie
comparator.call(key, value, object)
end
+ private_class_method :_match_comparator?
end
end
end
diff --git a/lib/hashie/extensions/deep_merge.rb b/lib/hashie/extensions/deep_merge.rb
index 5d8fe34..5363904 100644
--- a/lib/hashie/extensions/deep_merge.rb
+++ b/lib/hashie/extensions/deep_merge.rb
@@ -20,15 +20,14 @@ module Hashie
def _recursive_merge(hash, other_hash, &block)
other_hash.each do |k, v|
- hash[k] = if hash.key?(k) && hash[k].is_a?(::Hash) && v.is_a?(::Hash)
- _recursive_merge(hash[k], v, &block)
- else
- if hash.key?(k) && block_given?
- block.call(k, hash[k], v)
- else
- v.respond_to?(:deep_dup) ? v.deep_dup : v
- end
- end
+ hash[k] =
+ if hash.key?(k) && hash[k].is_a?(::Hash) && v.is_a?(::Hash)
+ _recursive_merge(hash[k], v, &block)
+ elsif hash.key?(k) && block_given?
+ yield(k, hash[k], v)
+ else
+ v.respond_to?(:deep_dup) ? v.deep_dup : v
+ end
end
hash
end
diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb
index e6e670a..4f5bd2c 100644
--- a/lib/hashie/extensions/indifferent_access.rb
+++ b/lib/hashie/extensions/indifferent_access.rb
@@ -32,12 +32,12 @@ module Hashie
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
alias_method :[]=, :indifferent_writer
alias_method :store, :indifferent_writer
- %w(default update replace fetch delete key? values_at).each do |m|
+ %w[default update replace fetch delete key? values_at].each do |m|
alias_method "regular_#{m}", m unless method_defined?("regular_#{m}")
alias_method m, "indifferent_#{m}"
end
- %w(include? member? has_key?).each do |key_alias|
+ %w[include? member? has_key?].each do |key_alias|
alias_method key_alias, :indifferent_key?
end
@@ -75,7 +75,7 @@ module Hashie
# their proper indifferent state. Used when IndifferentAccess
# is injecting itself into member hashes.
def convert!
- keys.each do |k|
+ keys.each do |k| # rubocop:disable Performance/HashEachMethods
regular_writer convert_key(k), indifferent_value(regular_delete(k))
end
self
diff --git a/lib/hashie/extensions/mash/keep_original_keys.rb b/lib/hashie/extensions/mash/keep_original_keys.rb
index 1b529a7..91b9b44 100644
--- a/lib/hashie/extensions/mash/keep_original_keys.rb
+++ b/lib/hashie/extensions/mash/keep_original_keys.rb
@@ -14,14 +14,12 @@ module Hashie
# mash['string_key'] == mash[:string_key] #=> true
# mash[:symbol_key] == mash['symbol_key'] #=> true
module KeepOriginalKeys
- private
-
def self.included(descendant)
- unless descendant <= Hashie::Mash
- fail ArgumentError, "#{descendant} is not a kind of Hashie::Mash"
- end
+ raise ArgumentError, "#{descendant} is not a kind of Hashie::Mash" unless descendant <= Hashie::Mash
end
+ private
+
# Converts the key when necessary to access the correct Mash key.
#
# @param [Object, String, Symbol] key the key to access.
diff --git a/lib/hashie/extensions/mash/safe_assignment.rb b/lib/hashie/extensions/mash/safe_assignment.rb
index 10a57dd..b1b2046 100644
--- a/lib/hashie/extensions/mash/safe_assignment.rb
+++ b/lib/hashie/extensions/mash/safe_assignment.rb
@@ -3,7 +3,7 @@ module Hashie
module Mash
module SafeAssignment
def custom_writer(key, *args) #:nodoc:
- fail ArgumentError, "The property #{key} clashes with an existing method." if !key?(key) && respond_to?(key, true)
+ raise ArgumentError, "The property #{key} clashes with an existing method." if !key?(key) && respond_to?(key, true)
super
end
diff --git a/lib/hashie/extensions/mash/symbolize_keys.rb b/lib/hashie/extensions/mash/symbolize_keys.rb
index 4e1d2be..91a6b14 100644
--- a/lib/hashie/extensions/mash/symbolize_keys.rb
+++ b/lib/hashie/extensions/mash/symbolize_keys.rb
@@ -19,7 +19,7 @@ module Hashie
# @return [void]
# @raise [ArgumentError] when the base class isn't a Mash
def self.included(base)
- fail ArgumentError, "#{base} must descent from Hashie::Mash" unless base <= Hashie::Mash
+ raise ArgumentError, "#{base} must descent from Hashie::Mash" unless base <= Hashie::Mash
end
private
diff --git a/lib/hashie/extensions/method_access.rb b/lib/hashie/extensions/method_access.rb
index 0ed2b22..e1ad56a 100644
--- a/lib/hashie/extensions/method_access.rb
+++ b/lib/hashie/extensions/method_access.rb
@@ -27,7 +27,7 @@ module Hashie
#
# user.not_declared # => NoMethodError
module MethodReader
- def respond_to?(name, include_private = false)
+ def respond_to_missing?(name, include_private = false)
return true if key?(name.to_s) || key?(name.to_sym)
super
end
@@ -67,15 +67,13 @@ module Hashie
# h['awesome'] # => 'sauce'
#
module MethodWriter
- def respond_to?(name, include_private = false)
+ def respond_to_missing?(name, include_private = false)
return true if name.to_s =~ /=$/
super
end
def method_missing(name, *args)
- if args.size == 1 && name.to_s =~ /(.*)=$/
- return self[convert_key(Regexp.last_match[1])] = args.first
- end
+ return self[convert_key(Regexp.last_match[1])] = args.first if args.size == 1 && name.to_s =~ /(.*)=$/
super
end
@@ -106,7 +104,7 @@ module Hashie
# h.def? # => false
# h.hji? # => NoMethodError
module MethodQuery
- def respond_to?(name, include_private = false)
+ def respond_to_missing?(name, include_private = false)
if query_method?(name) && indifferent_key?(key_from_query_method(name))
true
else
diff --git a/lib/hashie/extensions/parsers/yaml_erb_parser.rb b/lib/hashie/extensions/parsers/yaml_erb_parser.rb
index c0dda75..c2808de 100644
--- a/lib/hashie/extensions/parsers/yaml_erb_parser.rb
+++ b/lib/hashie/extensions/parsers/yaml_erb_parser.rb
@@ -14,7 +14,7 @@ module Hashie
def perform
template = ERB.new(@content)
template.filename = @file_path
- YAML.load template.result
+ YAML.safe_load template.result
end
def self.perform(file_path)
diff --git a/lib/hashie/extensions/strict_key_access.rb b/lib/hashie/extensions/strict_key_access.rb
index 78f86f3..0822c53 100644
--- a/lib/hashie/extensions/strict_key_access.rb
+++ b/lib/hashie/extensions/strict_key_access.rb
@@ -46,27 +46,26 @@ module Hashie
end
def default(_ = nil)
- fail DefaultError
+ raise DefaultError
end
def default=(_)
- fail DefaultError
+ raise DefaultError
end
def default_proc
- fail DefaultError
+ raise DefaultError
end
def default_proc=(_)
- fail DefaultError
+ raise DefaultError
end
def key(value)
- result = super
- if result.nil? && (!key?(result) || self[result] != value)
- fail KeyError, "key not found with value of #{value.inspect}"
- else
- result
+ super.tap do |result|
+ if result.nil? && (!key?(result) || self[result] != value)
+ raise KeyError, "key not found with value of #{value.inspect}"
+ end
end
end
end
diff --git a/lib/hashie/extensions/stringify_keys.rb b/lib/hashie/extensions/stringify_keys.rb
index 41b0fe3..bad29b6 100644
--- a/lib/hashie/extensions/stringify_keys.rb
+++ b/lib/hashie/extensions/stringify_keys.rb
@@ -44,7 +44,7 @@ module Hashie
# test # => {'abc' => 'def'}
def stringify_keys!(hash)
hash.extend(Hashie::Extensions::StringifyKeys) unless hash.respond_to?(:stringify_keys!)
- hash.keys.each do |k|
+ hash.keys.each do |k| # rubocop:disable Performance/HashEachMethods
stringify_keys_recursively!(hash[k])
hash[k.to_s] = hash.delete(k)
end
diff --git a/lib/hashie/extensions/symbolize_keys.rb b/lib/hashie/extensions/symbolize_keys.rb
index 274889c..e4315bd 100644
--- a/lib/hashie/extensions/symbolize_keys.rb
+++ b/lib/hashie/extensions/symbolize_keys.rb
@@ -44,7 +44,7 @@ module Hashie
# test # => {:abc => 'def'}
def symbolize_keys!(hash)
hash.extend(Hashie::Extensions::SymbolizeKeys) unless hash.respond_to?(:symbolize_keys!)
- hash.keys.each do |k|
+ hash.keys.each do |k| # rubocop:disable Performance/HashEachMethods
symbolize_keys_recursively!(hash[k])
hash[k.to_sym] = hash.delete(k)
end
diff --git a/lib/hashie/hash.rb b/lib/hashie/hash.rb
index 87e1923..0eade03 100644
--- a/lib/hashie/hash.rb
+++ b/lib/hashie/hash.rb
@@ -17,7 +17,7 @@ module Hashie
# Converts a mash back to a hash (with stringified or symbolized keys)
def to_hash(options = {})
out = {}
- keys.each do |k|
+ each_key do |k|
assignment_key = if options[:stringify_keys]
k.to_s
elsif options[:symbolize_keys]
@@ -28,10 +28,10 @@ module Hashie
if self[k].is_a?(Array)
out[assignment_key] ||= []
self[k].each do |array_object|
- out[assignment_key] << (Hash === array_object ? flexibly_convert_to_hash(array_object, options) : array_object)
+ out[assignment_key] << (array_object.is_a?(Hash) ? flexibly_convert_to_hash(array_object, options) : array_object)
end
else
- out[assignment_key] = (Hash === self[k] || self[k].respond_to?(:to_hash)) ? flexibly_convert_to_hash(self[k], options) : self[k]
+ out[assignment_key] = self[k].is_a?(Hash) || self[k].respond_to?(:to_hash) ? flexibly_convert_to_hash(self[k], options) : self[k]
end
end
out
@@ -45,7 +45,7 @@ module Hashie
private
def flexibly_convert_to_hash(object, options = {})
- if object.method(:to_hash).arity == 0
+ if object.method(:to_hash).arity.zero?
object.to_hash
else
object.to_hash(options)
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
diff --git a/lib/hashie/rash.rb b/lib/hashie/rash.rb
index 0024eee..a7fce10 100644
--- a/lib/hashie/rash.rb
+++ b/lib/hashie/rash.rb
@@ -64,7 +64,7 @@ module Hashie
# Raise (or yield) unless something matches the key.
#
def fetch(*args)
- fail ArgumentError, "Expected 1-2 arguments, got #{args.length}" \
+ raise ArgumentError, "Expected 1-2 arguments, got #{args.length}" \
unless (1..2).cover?(args.length)
key, default = args
@@ -78,7 +78,7 @@ module Hashie
elsif default
default
else
- fail KeyError, "key not found: #{key.inspect}"
+ raise KeyError, "key not found: #{key.inspect}"
end
end
@@ -125,11 +125,11 @@ module Hashie
end
def method_missing(*args, &block)
- @hash.send(*args, &block)
+ @hash.send(*args, &block) || super
end
- def respond_to_missing?(*args)
- @hash.respond_to?(*args)
+ def respond_to_missing?(method_name, _include_private = false)
+ @hash.respond_to?(method_name)
end
private
diff --git a/lib/hashie/version.rb b/lib/hashie/version.rb
index cb6dd4e..6e8e934 100644
--- a/lib/hashie/version.rb
+++ b/lib/hashie/version.rb
@@ -1,3 +1,3 @@
module Hashie
- VERSION = '3.5.8'
+ VERSION = '3.5.8'.freeze
end