diff options
author | Bobby McDonald <bobbymcwho@gmail.com> | 2019-10-17 23:51:50 -0400 |
---|---|---|
committer | Bobby McDonald <bobbymcwho@gmail.com> | 2019-10-17 23:55:45 -0400 |
commit | 6a965273845f64605e0e951ac113a4383f7e8af5 (patch) | |
tree | 56c0f813cefe071fdcc25756275636c58e8beb3b /lib/hashie | |
parent | 20e5467188bb4b6ab4166a72c07ec2bc0b883fa0 (diff) | |
download | hashie-6a965273845f64605e0e951ac113a4383f7e8af5.tar.gz |
Change rubocop to allow 100 character lines.
For accessibility reasons, we should limit our lines to 100 chars max.
https://github.com/slack-ruby/slack-ruby-client/pull/293#discussion_r309472083
Diffstat (limited to 'lib/hashie')
-rw-r--r-- | lib/hashie/dash.rb | 3 | ||||
-rw-r--r-- | lib/hashie/extensions/coercion.rb | 7 | ||||
-rw-r--r-- | lib/hashie/extensions/dash/property_translation.rb | 3 | ||||
-rw-r--r-- | lib/hashie/extensions/deep_fetch.rb | 6 | ||||
-rw-r--r-- | lib/hashie/extensions/deep_find.rb | 15 | ||||
-rw-r--r-- | lib/hashie/extensions/deep_locate.rb | 23 | ||||
-rw-r--r-- | lib/hashie/extensions/mash/keep_original_keys.rb | 3 | ||||
-rw-r--r-- | lib/hashie/extensions/method_access.rb | 7 | ||||
-rw-r--r-- | lib/hashie/extensions/strict_key_access.rb | 7 | ||||
-rw-r--r-- | lib/hashie/rash.rb | 2 |
10 files changed, 52 insertions, 24 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 4e366ed..460790b 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -219,7 +219,8 @@ module Hashie end def fail_property_required_error!(property) - raise 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) diff --git a/lib/hashie/extensions/coercion.rb b/lib/hashie/extensions/coercion.rb index 88be97a..a12490a 100644 --- a/lib/hashie/extensions/coercion.rb +++ b/lib/hashie/extensions/coercion.rb @@ -21,8 +21,8 @@ module Hashie { Numeric => [Integer, Float, Complex, Rational] } else { - Integer => [Fixnum, Bignum], # rubocop:disable Lint/UnifiedInteger - Numeric => [Fixnum, Bignum, Float, Complex, Rational] # rubocop:disable Lint/UnifiedInteger + Integer => [Fixnum, Bignum], + Numeric => [Fixnum, Bignum, Float, Complex, Rational] } end @@ -103,7 +103,8 @@ module Hashie # # @param [Class] from the type you would like coerced. # @param [Class] into the class into which you would like the value coerced. - # @option options [Boolean] :strict (true) whether use exact source class only or include ancestors + # @option options [Boolean] :strict (true) whether use exact source class + # only or include ancestors # # @example Coerce all hashes into this special type of hash # class SpecialHash < Hash diff --git a/lib/hashie/extensions/dash/property_translation.rb b/lib/hashie/extensions/dash/property_translation.rb index f5bf081..c0fd009 100644 --- a/lib/hashie/extensions/dash/property_translation.rb +++ b/lib/hashie/extensions/dash/property_translation.rb @@ -137,7 +137,8 @@ module Hashie end def fail_self_transformation_error!(property_name) - raise 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 def valid_transformer?(transformer) diff --git a/lib/hashie/extensions/deep_fetch.rb b/lib/hashie/extensions/deep_fetch.rb index 6ed34f3..6131e8d 100644 --- a/lib/hashie/extensions/deep_fetch.rb +++ b/lib/hashie/extensions/deep_fetch.rb @@ -9,7 +9,8 @@ module Hashie # # options.deep_fetch(:user, :non_existent_key) { 'a value' } #=> 'a value' # - # This is particularly useful for fetching values from deeply nested api responses or params hashes. + # This is particularly useful for fetching values from deeply nested api responses + # or params hashes. module DeepFetch class UndefinedPathError < StandardError; end @@ -20,7 +21,8 @@ module Hashie obj.fetch(arg) rescue ArgumentError, IndexError, NoMethodError => e break yield(arg) if block - raise UndefinedPathError, "Could not fetch path (#{args.join(' > ')}) at #{arg}", e.backtrace + raise UndefinedPathError, + "Could not fetch path (#{args.join(' > ')}) at #{arg}", e.backtrace end end end diff --git a/lib/hashie/extensions/deep_find.rb b/lib/hashie/extensions/deep_find.rb index c4a7646..0e77932 100644 --- a/lib/hashie/extensions/deep_find.rb +++ b/lib/hashie/extensions/deep_find.rb @@ -1,3 +1,4 @@ +require 'hashie/extensions/deep_locate' module Hashie module Extensions module DeepFind @@ -24,7 +25,12 @@ module Hashie # Performs a depth-first search on deeply nested data structures for # a key and returns all occurrences of the key. # - # options = {users: [{location: {address: '123 Street'}}, {location: {address: '234 Street'}}]} + # options = { + # users: [ + # { location: {address: '123 Street'} }, + # { location: {address: '234 Street'}} + # ] + # } # options.extend(Hashie::Extensions::DeepFind) # options.deep_find_all(:address) # => ['123 Street', '234 Street'] # @@ -33,7 +39,10 @@ module Hashie # end # # my_hash = MyHash.new - # my_hash[:users] = [{location: {address: '123 Street'}}, {location: {address: '234 Street'}}] + # my_hash[:users] = [ + # {location: {address: '123 Street'}}, + # {location: {address: '234 Street'}} + # ] # my_hash.deep_find_all(:address) # => ['123 Street', '234 Street'] def deep_find_all(key) matches = _deep_find_all(key) @@ -49,7 +58,7 @@ module Hashie end def _deep_find_all(key, object = self, matches = []) - deep_locate_result = Hashie::Extensions::DeepLocate.deep_locate(key, object).tap do |result| + deep_locate_result = DeepLocate.deep_locate(key, object).tap do |result| result.map! { |element| element[key] } end diff --git a/lib/hashie/extensions/deep_locate.rb b/lib/hashie/extensions/deep_locate.rb index 62e1be2..2b33b23 100644 --- a/lib/hashie/extensions/deep_locate.rb +++ b/lib/hashie/extensions/deep_locate.rb @@ -14,10 +14,12 @@ module Hashie # ... # ] # - # Hashie::Extensions::DeepLocate.deep_locate -> (key, value, object) { key == :title }, books + # DeepLocate.deep_locate -> (key, value, object) { key == :title }, books # # => [{:title=>"Ruby for beginners", :pages=>120}, ...] def self.deep_locate(comparator, object) - comparator = _construct_key_comparator(comparator, object) unless comparator.respond_to?(:call) + unless comparator.respond_to?(:call) + comparator = _construct_key_comparator(comparator, object) + end _deep_locate(comparator, object) end @@ -53,17 +55,21 @@ module Hashie # # http://ruby-journal.com/becareful-with-space-in-lambda-hash-rocket-syntax-between-ruby-1-dot-9-and-2-dot-0/ # # books.deep_locate -> (key, value, object) { key == :title && value.include?("Ruby") } - # # => [{:title=>"Ruby for beginners", :pages=>120}, {:title=>"Ruby for the rest of us", :pages=>576}] + # # => [{:title=>"Ruby for beginners", :pages=>120}, + # # {:title=>"Ruby for the rest of us", :pages=>576}] # # books.deep_locate -> (key, value, object) { key == :pages && value <= 120 } - # # => [{:title=>"Ruby for beginners", :pages=>120}, {:title=>"CSS for intermediates", :pages=>80}] + # # => [{:title=>"Ruby for beginners", :pages=>120}, + # # {:title=>"CSS for intermediates", :pages=>80}] def deep_locate(comparator) Hashie::Extensions::DeepLocate.deep_locate(comparator, self) end def self._construct_key_comparator(search_key, object) - search_key = search_key.to_s if activesupport_indifferent?(object) - search_key = search_key.to_s if object.respond_to?(:indifferent_access?) && object.indifferent_access? + if object.respond_to?(:indifferent_access?) && object.indifferent_access? || + activesupport_indifferent?(object) + search_key = search_key.to_s + end lambda do |non_callable_object| ->(key, _, _) { key == non_callable_object } @@ -73,7 +79,10 @@ module Hashie def self._deep_locate(comparator, object, result = []) if object.is_a?(::Enumerable) - result.push object if object.any? { |value| _match_comparator?(value, comparator, object) } + if object.any? { |value| _match_comparator?(value, comparator, object) } + result.push object + end + (object.respond_to?(:values) ? object.values : object.entries).each do |value| _deep_locate(comparator, value, result) end diff --git a/lib/hashie/extensions/mash/keep_original_keys.rb b/lib/hashie/extensions/mash/keep_original_keys.rb index 91b9b44..e25d8f9 100644 --- a/lib/hashie/extensions/mash/keep_original_keys.rb +++ b/lib/hashie/extensions/mash/keep_original_keys.rb @@ -15,7 +15,8 @@ module Hashie # mash[:symbol_key] == mash['symbol_key'] #=> true module KeepOriginalKeys def self.included(descendant) - raise ArgumentError, "#{descendant} is not a kind of Hashie::Mash" unless descendant <= Hashie::Mash + error_message = "#{descendant} is not a kind of Hashie::Mash" + raise ArgumentError, error_message unless descendant <= Hashie::Mash end private diff --git a/lib/hashie/extensions/method_access.rb b/lib/hashie/extensions/method_access.rb index cf13da0..6543fee 100644 --- a/lib/hashie/extensions/method_access.rb +++ b/lib/hashie/extensions/method_access.rb @@ -73,7 +73,9 @@ module Hashie end def method_missing(name, *args) - return self[convert_key(Regexp.last_match[1])] = args.first if args.size == 1 && name.to_s =~ /(.*)=$/ + if args.size == 1 && name.to_s =~ /(.*)=$/ + return self[convert_key(Regexp.last_match[1])] = args.first + end super end @@ -231,7 +233,8 @@ module Hashie # underscores. module MethodAccessWithOverride def self.included(base) - [MethodReader, MethodOverridingWriter, MethodQuery, MethodOverridingInitializer].each do |mod| + [MethodReader, MethodOverridingWriter, + MethodQuery, MethodOverridingInitializer].each do |mod| base.send :include, mod end end diff --git a/lib/hashie/extensions/strict_key_access.rb b/lib/hashie/extensions/strict_key_access.rb index 0edd698..4593b3f 100644 --- a/lib/hashie/extensions/strict_key_access.rb +++ b/lib/hashie/extensions/strict_key_access.rb @@ -1,6 +1,7 @@ module Hashie module Extensions - # SRP: This extension will fail an error whenever a key is accessed that does not exist in the hash. + # SRP: This extension will fail an error whenever a key is accessed + # that does not exist in the hash. # # EXAMPLE: # @@ -21,8 +22,8 @@ module Hashie module StrictKeyAccess class DefaultError < StandardError def initialize - super( - 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense' + super('Setting or using a default with Hashie::Extensions::StrictKeyAccess'\ + ' does not make sense' ) end end diff --git a/lib/hashie/rash.rb b/lib/hashie/rash.rb index a7fce10..2141684 100644 --- a/lib/hashie/rash.rb +++ b/lib/hashie/rash.rb @@ -117,7 +117,7 @@ module Hashie end when Regexp - # Reverse operation: `rash[/regexp/]` returns all the hash's string keys which match the regexp + # Reverse operation: `rash[/regexp/]` returns all string keys matching the regexp @hash.each do |key, val| yield val if key.is_a?(String) && query =~ key end |