hashie 3.6.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +271 -207
- data/CONTRIBUTING.md +13 -6
- data/LICENSE +1 -1
- data/README.md +245 -54
- data/UPGRADING.md +121 -7
- data/hashie.gemspec +13 -7
- data/lib/hashie/dash.rb +18 -17
- data/lib/hashie/extensions/active_support/core_ext/hash.rb +14 -0
- data/lib/hashie/extensions/coercion.rb +23 -16
- data/lib/hashie/extensions/dash/indifferent_access.rb +29 -1
- data/lib/hashie/extensions/dash/predefined_values.rb +88 -0
- data/lib/hashie/extensions/dash/property_translation.rb +12 -4
- data/lib/hashie/extensions/deep_fetch.rb +4 -2
- data/lib/hashie/extensions/deep_find.rb +12 -3
- data/lib/hashie/extensions/deep_locate.rb +22 -7
- data/lib/hashie/extensions/deep_merge.rb +18 -1
- data/lib/hashie/extensions/ignore_undeclared.rb +4 -5
- data/lib/hashie/extensions/indifferent_access.rb +37 -6
- data/lib/hashie/extensions/key_conflict_warning.rb +55 -0
- data/lib/hashie/extensions/mash/define_accessors.rb +90 -0
- data/lib/hashie/extensions/mash/keep_original_keys.rb +2 -1
- data/lib/hashie/extensions/mash/permissive_respond_to.rb +61 -0
- data/lib/hashie/extensions/mash/safe_assignment.rb +3 -1
- data/lib/hashie/extensions/mash/symbolize_keys.rb +5 -5
- data/lib/hashie/extensions/method_access.rb +5 -2
- data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +26 -4
- data/lib/hashie/extensions/ruby_version_check.rb +5 -1
- data/lib/hashie/extensions/strict_key_access.rb +8 -4
- data/lib/hashie/extensions/symbolize_keys.rb +12 -1
- data/lib/hashie/hash.rb +16 -9
- data/lib/hashie/mash.rb +130 -64
- data/lib/hashie/railtie.rb +7 -0
- data/lib/hashie/rash.rb +1 -1
- data/lib/hashie/utils.rb +28 -0
- data/lib/hashie/version.rb +1 -1
- data/lib/hashie.rb +22 -19
- metadata +23 -133
- data/spec/hashie/array_spec.rb +0 -29
- data/spec/hashie/clash_spec.rb +0 -70
- data/spec/hashie/dash_spec.rb +0 -598
- data/spec/hashie/extensions/autoload_spec.rb +0 -24
- data/spec/hashie/extensions/coercion_spec.rb +0 -639
- data/spec/hashie/extensions/dash/coercion_spec.rb +0 -13
- data/spec/hashie/extensions/dash/indifferent_access_spec.rb +0 -84
- data/spec/hashie/extensions/deep_fetch_spec.rb +0 -97
- data/spec/hashie/extensions/deep_find_spec.rb +0 -138
- data/spec/hashie/extensions/deep_locate_spec.rb +0 -137
- data/spec/hashie/extensions/deep_merge_spec.rb +0 -70
- data/spec/hashie/extensions/ignore_undeclared_spec.rb +0 -47
- data/spec/hashie/extensions/indifferent_access_spec.rb +0 -295
- data/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +0 -208
- data/spec/hashie/extensions/key_conversion_spec.rb +0 -12
- data/spec/hashie/extensions/mash/keep_original_keys_spec.rb +0 -46
- data/spec/hashie/extensions/mash/safe_assignment_spec.rb +0 -50
- data/spec/hashie/extensions/mash/symbolize_keys_spec.rb +0 -39
- data/spec/hashie/extensions/merge_initializer_spec.rb +0 -23
- data/spec/hashie/extensions/method_access_spec.rb +0 -226
- data/spec/hashie/extensions/strict_key_access_spec.rb +0 -110
- data/spec/hashie/extensions/stringify_keys_spec.rb +0 -124
- data/spec/hashie/extensions/symbolize_keys_spec.rb +0 -129
- data/spec/hashie/hash_spec.rb +0 -84
- data/spec/hashie/mash_spec.rb +0 -771
- data/spec/hashie/parsers/yaml_erb_parser_spec.rb +0 -46
- data/spec/hashie/rash_spec.rb +0 -83
- data/spec/hashie/trash_spec.rb +0 -328
- data/spec/hashie/utils_spec.rb +0 -25
- data/spec/hashie/version_spec.rb +0 -7
- data/spec/hashie_spec.rb +0 -13
- data/spec/integration/elasticsearch/integration_spec.rb +0 -40
- data/spec/integration/omniauth/app.rb +0 -11
- data/spec/integration/omniauth/integration_spec.rb +0 -38
- data/spec/integration/omniauth-oauth2/app.rb +0 -52
- data/spec/integration/omniauth-oauth2/integration_spec.rb +0 -26
- data/spec/integration/omniauth-oauth2/some_site.rb +0 -38
- data/spec/integration/rails/app.rb +0 -47
- data/spec/integration/rails/integration_spec.rb +0 -26
- data/spec/integration/rails-without-dependency/integration_spec.rb +0 -15
- data/spec/spec_helper.rb +0 -23
- data/spec/support/integration_specs.rb +0 -36
- data/spec/support/logger.rb +0 -24
- data/spec/support/module_context.rb +0 -11
- data/spec/support/ruby_version_check.rb +0 -6
data/lib/hashie/mash.rb
CHANGED
@@ -2,6 +2,7 @@ require 'hashie/hash'
|
|
2
2
|
require 'hashie/array'
|
3
3
|
require 'hashie/utils'
|
4
4
|
require 'hashie/logger'
|
5
|
+
require 'hashie/extensions/key_conflict_warning'
|
5
6
|
|
6
7
|
module Hashie
|
7
8
|
# Mash allows you to create pseudo-objects that have method-like
|
@@ -15,9 +16,12 @@ module Hashie
|
|
15
16
|
#
|
16
17
|
# * No punctuation: Returns the value of the hash for that key, or nil if none exists.
|
17
18
|
# * Assignment (<tt>=</tt>): Sets the attribute of the given method name.
|
18
|
-
# *
|
19
|
-
#
|
20
|
-
# *
|
19
|
+
# * Truthiness (<tt>?</tt>): Returns true or false depending on the truthiness of
|
20
|
+
# the attribute, or false if the key is not set.
|
21
|
+
# * Bang (<tt>!</tt>): Forces the existence of this key, used for deep Mashes. Think of it
|
22
|
+
# as "touch" for mashes.
|
23
|
+
# * Under Bang (<tt>_</tt>): Like Bang, but returns a new Mash rather than creating a key.
|
24
|
+
# Used to test existance in deep Mashes.
|
21
25
|
#
|
22
26
|
# == Basic Example
|
23
27
|
#
|
@@ -58,51 +62,20 @@ module Hashie
|
|
58
62
|
# mash.author # => <Mash>
|
59
63
|
#
|
60
64
|
class Mash < Hash
|
61
|
-
include Hashie::Extensions::PrettyInspect
|
62
65
|
include Hashie::Extensions::RubyVersionCheck
|
66
|
+
extend Hashie::Extensions::KeyConflictWarning
|
63
67
|
|
64
68
|
ALLOWED_SUFFIXES = %w[? ! = _].freeze
|
65
69
|
|
66
|
-
class CannotDisableMashWarnings < StandardError
|
67
|
-
def initialize(message = 'You cannot disable warnings on the base Mash class. Please subclass the Mash and disable it in the subclass.')
|
68
|
-
super(message)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Disable the logging of warnings based on keys conflicting keys/methods
|
73
|
-
#
|
74
|
-
# @api semipublic
|
75
|
-
# @return [void]
|
76
|
-
def self.disable_warnings
|
77
|
-
raise CannotDisableMashWarnings if self == Hashie::Mash
|
78
|
-
@disable_warnings = true
|
79
|
-
end
|
80
|
-
|
81
|
-
# Checks whether this class disables warnings for conflicting keys/methods
|
82
|
-
#
|
83
|
-
# @api semipublic
|
84
|
-
# @return [Boolean]
|
85
|
-
def self.disable_warnings?
|
86
|
-
@disable_warnings ||= false
|
87
|
-
end
|
88
|
-
|
89
|
-
# Inheritance hook that sets class configuration when inherited.
|
90
|
-
#
|
91
|
-
# @api semipublic
|
92
|
-
# @return [void]
|
93
|
-
def self.inherited(subclass)
|
94
|
-
super
|
95
|
-
subclass.disable_warnings if disable_warnings?
|
96
|
-
end
|
97
|
-
|
98
70
|
def self.load(path, options = {})
|
99
71
|
@_mashes ||= new
|
100
72
|
|
101
73
|
return @_mashes[path] if @_mashes.key?(path)
|
102
74
|
raise ArgumentError, "The following file doesn't exist: #{path}" unless File.file?(path)
|
103
75
|
|
104
|
-
|
105
|
-
|
76
|
+
options = options.dup
|
77
|
+
parser = options.delete(:parser) { Hashie::Extensions::Parsers::YamlErbParser }
|
78
|
+
@_mashes[path] = new(parser.perform(path, options)).freeze
|
106
79
|
end
|
107
80
|
|
108
81
|
def to_module(mash_method_name = :settings)
|
@@ -114,6 +87,10 @@ module Hashie
|
|
114
87
|
end
|
115
88
|
end
|
116
89
|
|
90
|
+
def with_accessors!
|
91
|
+
extend Hashie::Extensions::Mash::DefineAccessors
|
92
|
+
end
|
93
|
+
|
117
94
|
alias to_s inspect
|
118
95
|
|
119
96
|
# If you pass in an existing hash, it will
|
@@ -125,13 +102,26 @@ module Hashie
|
|
125
102
|
default ? super(default) : super(&blk)
|
126
103
|
end
|
127
104
|
|
105
|
+
# Creates a new anonymous subclass with key conflict
|
106
|
+
# warnings disabled. You may pass an array of method
|
107
|
+
# symbols to restrict the disabled warnings to.
|
108
|
+
# Hashie::Mash.quiet.new(hash) all warnings disabled.
|
109
|
+
# Hashie::Mash.quiet(:zip).new(hash) only zip warning
|
110
|
+
# is disabled.
|
111
|
+
def self.quiet(*method_keys)
|
112
|
+
@memoized_classes ||= {}
|
113
|
+
@memoized_classes[method_keys] ||= Class.new(self) do
|
114
|
+
disable_warnings(*method_keys)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
128
118
|
class << self; alias [] new; end
|
129
119
|
|
130
120
|
alias regular_reader []
|
131
121
|
alias regular_writer []=
|
132
122
|
|
133
|
-
# Retrieves an attribute set in the Mash. Will convert
|
134
|
-
#
|
123
|
+
# Retrieves an attribute set in the Mash. Will convert a key passed in
|
124
|
+
# as a symbol to a string before retrieving.
|
135
125
|
def custom_reader(key)
|
136
126
|
default_proc.call(self, key) if default_proc && !key?(key)
|
137
127
|
value = regular_reader(convert_key(key))
|
@@ -139,14 +129,12 @@ module Hashie
|
|
139
129
|
value
|
140
130
|
end
|
141
131
|
|
142
|
-
# Sets an attribute in the Mash.
|
143
|
-
#
|
144
|
-
#
|
132
|
+
# Sets an attribute in the Mash. Symbol keys will be converted to
|
133
|
+
# strings before being set, and Hashes will be converted into Mashes
|
134
|
+
# for nesting purposes.
|
145
135
|
def custom_writer(key, value, convert = true) #:nodoc:
|
146
|
-
|
147
|
-
|
148
|
-
log_built_in_message(key_as_symbol) if log_collision?(key_as_symbol)
|
149
|
-
regular_writer(key, convert ? convert_value(value) : value)
|
136
|
+
log_built_in_message(key) if key.respond_to?(:to_sym) && log_collision?(key.to_sym)
|
137
|
+
regular_writer(convert_key(key), convert ? convert_value(value) : value)
|
150
138
|
end
|
151
139
|
|
152
140
|
alias [] custom_reader
|
@@ -183,6 +171,25 @@ module Hashie
|
|
183
171
|
super(*keys.map { |key| convert_key(key) })
|
184
172
|
end
|
185
173
|
|
174
|
+
# Returns a new instance of the class it was called on, using its keys as
|
175
|
+
# values, and its values as keys. The new values and keys will always be
|
176
|
+
# strings.
|
177
|
+
def invert
|
178
|
+
self.class.new(super)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns a new instance of the class it was called on, containing elements
|
182
|
+
# for which the given block returns false.
|
183
|
+
def reject(&blk)
|
184
|
+
self.class.new(super(&blk))
|
185
|
+
end
|
186
|
+
|
187
|
+
# Returns a new instance of the class it was called on, containing elements
|
188
|
+
# for which the given block returns true.
|
189
|
+
def select(&blk)
|
190
|
+
self.class.new(super(&blk))
|
191
|
+
end
|
192
|
+
|
186
193
|
alias regular_dup dup
|
187
194
|
# Duplicates the current mash as a new mash.
|
188
195
|
def dup
|
@@ -197,19 +204,47 @@ module Hashie
|
|
197
204
|
alias include? key?
|
198
205
|
alias member? key?
|
199
206
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
207
|
+
if with_minimum_ruby?('2.6.0')
|
208
|
+
# Performs a deep_update on a duplicate of the
|
209
|
+
# current mash.
|
210
|
+
def deep_merge(*other_hashes, &blk)
|
211
|
+
dup.deep_update(*other_hashes, &blk)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Recursively merges this mash with the passed
|
215
|
+
# in hash, merging each hash in the hierarchy.
|
216
|
+
def deep_update(*other_hashes, &blk)
|
217
|
+
other_hashes.each do |other_hash|
|
218
|
+
_deep_update(other_hash, &blk)
|
219
|
+
end
|
220
|
+
self
|
221
|
+
end
|
222
|
+
else
|
223
|
+
# Performs a deep_update on a duplicate of the
|
224
|
+
# current mash.
|
225
|
+
def deep_merge(other_hash, &blk)
|
226
|
+
dup.deep_update(other_hash, &blk)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Recursively merges this mash with the passed
|
230
|
+
# in hash, merging each hash in the hierarchy.
|
231
|
+
def deep_update(other_hash, &blk)
|
232
|
+
_deep_update(other_hash, &blk)
|
233
|
+
self
|
234
|
+
end
|
204
235
|
end
|
236
|
+
|
237
|
+
# Alias these lexically so they get the correctly defined
|
238
|
+
# #deep_merge and #deep_update based on ruby version.
|
205
239
|
alias merge deep_merge
|
240
|
+
alias deep_merge! deep_update
|
241
|
+
alias update deep_update
|
242
|
+
alias merge! update
|
206
243
|
|
207
|
-
|
208
|
-
# in hash, merging each hash in the hierarchy.
|
209
|
-
def deep_update(other_hash, &blk)
|
244
|
+
def _deep_update(other_hash, &blk)
|
210
245
|
other_hash.each_pair do |k, v|
|
211
246
|
key = convert_key(k)
|
212
|
-
if
|
247
|
+
if v.is_a?(::Hash) && key?(key) && regular_reader(key).is_a?(Mash)
|
213
248
|
custom_reader(key).deep_update(v, &blk)
|
214
249
|
else
|
215
250
|
value = convert_value(v, true)
|
@@ -217,11 +252,8 @@ module Hashie
|
|
217
252
|
custom_writer(key, value, false)
|
218
253
|
end
|
219
254
|
end
|
220
|
-
self
|
221
255
|
end
|
222
|
-
|
223
|
-
alias update deep_update
|
224
|
-
alias merge! update
|
256
|
+
private :_deep_update
|
225
257
|
|
226
258
|
# Assigns a value to a key
|
227
259
|
def assign_property(name, value)
|
@@ -296,6 +328,36 @@ module Hashie
|
|
296
328
|
end
|
297
329
|
end
|
298
330
|
|
331
|
+
with_minimum_ruby('2.4.0') do
|
332
|
+
def transform_values(&blk)
|
333
|
+
self.class.new(super(&blk))
|
334
|
+
end
|
335
|
+
|
336
|
+
# Returns a new instance of the class it was called on, with nil values
|
337
|
+
# removed.
|
338
|
+
def compact
|
339
|
+
self.class.new(super)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
with_minimum_ruby('2.5.0') do
|
344
|
+
def slice(*keys)
|
345
|
+
string_keys = keys.map { |key| convert_key(key) }
|
346
|
+
self.class.new(super(*string_keys))
|
347
|
+
end
|
348
|
+
|
349
|
+
def transform_keys(&blk)
|
350
|
+
self.class.new(super(&blk))
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
with_minimum_ruby('3.0.0') do
|
355
|
+
def except(*keys)
|
356
|
+
string_keys = keys.map { |key| convert_key(key) }
|
357
|
+
self.class.new(super(*string_keys))
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
299
361
|
protected
|
300
362
|
|
301
363
|
def method_name_and_suffix(method_name)
|
@@ -313,7 +375,7 @@ module Hashie
|
|
313
375
|
end
|
314
376
|
|
315
377
|
def convert_key(key) #:nodoc:
|
316
|
-
key.to_s
|
378
|
+
key.respond_to?(:to_sym) ? key.to_s : key
|
317
379
|
end
|
318
380
|
|
319
381
|
def convert_value(val, duping = false) #:nodoc:
|
@@ -325,8 +387,6 @@ module Hashie
|
|
325
387
|
when ::Hash
|
326
388
|
val = val.dup if duping
|
327
389
|
self.class.new(val)
|
328
|
-
when Array
|
329
|
-
val.map { |e| convert_value(e) }
|
330
390
|
when ::Array
|
331
391
|
Array.new(val.map { |e| convert_value(e) })
|
332
392
|
else
|
@@ -337,7 +397,7 @@ module Hashie
|
|
337
397
|
private
|
338
398
|
|
339
399
|
def log_built_in_message(method_key)
|
340
|
-
return if self.class.disable_warnings?
|
400
|
+
return if self.class.disable_warnings?(method_key)
|
341
401
|
|
342
402
|
method_information = Hashie::Utils.method_information(method(method_key))
|
343
403
|
|
@@ -350,7 +410,13 @@ module Hashie
|
|
350
410
|
end
|
351
411
|
|
352
412
|
def log_collision?(method_key)
|
353
|
-
|
413
|
+
return unless method_key.is_a?(String) || method_key.is_a?(Symbol)
|
414
|
+
return unless respond_to?(method_key)
|
415
|
+
|
416
|
+
_, suffix = method_name_and_suffix(method_key)
|
417
|
+
|
418
|
+
(!suffix || suffix == '='.freeze) &&
|
419
|
+
!self.class.disable_warnings?(method_key) &&
|
354
420
|
!(regular_key?(method_key) || regular_key?(method_key.to_s))
|
355
421
|
end
|
356
422
|
end
|
data/lib/hashie/railtie.rb
CHANGED
@@ -7,6 +7,13 @@ begin
|
|
7
7
|
initializer 'hashie.configure_logger', after: 'initialize_logger' do
|
8
8
|
Hashie.logger = Rails.logger
|
9
9
|
end
|
10
|
+
|
11
|
+
initializer 'hashie.patch_hash_except', after: 'load_active_support' do
|
12
|
+
if Rails::VERSION::MAJOR >= 6
|
13
|
+
require 'hashie/extensions/active_support/core_ext/hash'
|
14
|
+
Hashie::Mash.send(:include, Hashie::Extensions::ActiveSupport::CoreExt::Hash)
|
15
|
+
end
|
16
|
+
end
|
10
17
|
end
|
11
18
|
end
|
12
19
|
rescue LoadError => e
|
data/lib/hashie/rash.rb
CHANGED
@@ -117,7 +117,7 @@ module Hashie
|
|
117
117
|
end
|
118
118
|
|
119
119
|
when Regexp
|
120
|
-
# Reverse operation: `rash[/regexp/]` returns all
|
120
|
+
# Reverse operation: `rash[/regexp/]` returns all string keys matching the regexp
|
121
121
|
@hash.each do |key, val|
|
122
122
|
yield val if key.is_a?(String) && query =~ key
|
123
123
|
end
|
data/lib/hashie/utils.rb
CHANGED
@@ -12,5 +12,33 @@ module Hashie
|
|
12
12
|
"defined in #{bound_method.owner}"
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
# Duplicates a value or returns the value when it is not duplicable
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
#
|
20
|
+
# @param value [Object] the value to safely duplicate
|
21
|
+
# @return [Object] the duplicated value
|
22
|
+
def self.safe_dup(value)
|
23
|
+
case value
|
24
|
+
when Complex, FalseClass, NilClass, Rational, Method, Symbol, TrueClass, *integer_classes
|
25
|
+
value
|
26
|
+
else
|
27
|
+
value.dup
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Lists the classes Ruby uses for integers
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
# @return [Array<Class>]
|
35
|
+
def self.integer_classes
|
36
|
+
@integer_classes ||=
|
37
|
+
if 0.class == Integer
|
38
|
+
[Integer]
|
39
|
+
else
|
40
|
+
[Fixnum, Bignum] # rubocop:disable Lint/UnifiedInteger
|
41
|
+
end
|
42
|
+
end
|
15
43
|
end
|
16
44
|
end
|
data/lib/hashie/version.rb
CHANGED
data/lib/hashie.rb
CHANGED
@@ -12,26 +12,26 @@ module Hashie
|
|
12
12
|
autoload :Utils, 'hashie/utils'
|
13
13
|
|
14
14
|
module Extensions
|
15
|
-
autoload :Coercion,
|
16
|
-
autoload :DeepMerge,
|
17
|
-
autoload :IgnoreUndeclared,
|
18
|
-
autoload :IndifferentAccess,
|
19
|
-
autoload :MergeInitializer,
|
20
|
-
autoload :MethodAccess,
|
21
|
-
autoload :MethodQuery,
|
22
|
-
autoload :MethodReader,
|
23
|
-
autoload :MethodWriter,
|
24
|
-
autoload :StringifyKeys,
|
25
|
-
autoload :SymbolizeKeys,
|
26
|
-
autoload :DeepFetch,
|
27
|
-
autoload :DeepFind,
|
28
|
-
autoload :DeepLocate,
|
29
|
-
autoload :PrettyInspect,
|
30
|
-
autoload :KeyConversion,
|
15
|
+
autoload :Coercion, 'hashie/extensions/coercion'
|
16
|
+
autoload :DeepMerge, 'hashie/extensions/deep_merge'
|
17
|
+
autoload :IgnoreUndeclared, 'hashie/extensions/ignore_undeclared'
|
18
|
+
autoload :IndifferentAccess, 'hashie/extensions/indifferent_access'
|
19
|
+
autoload :MergeInitializer, 'hashie/extensions/merge_initializer'
|
20
|
+
autoload :MethodAccess, 'hashie/extensions/method_access'
|
21
|
+
autoload :MethodQuery, 'hashie/extensions/method_access'
|
22
|
+
autoload :MethodReader, 'hashie/extensions/method_access'
|
23
|
+
autoload :MethodWriter, 'hashie/extensions/method_access'
|
24
|
+
autoload :StringifyKeys, 'hashie/extensions/stringify_keys'
|
25
|
+
autoload :SymbolizeKeys, 'hashie/extensions/symbolize_keys'
|
26
|
+
autoload :DeepFetch, 'hashie/extensions/deep_fetch'
|
27
|
+
autoload :DeepFind, 'hashie/extensions/deep_find'
|
28
|
+
autoload :DeepLocate, 'hashie/extensions/deep_locate'
|
29
|
+
autoload :PrettyInspect, 'hashie/extensions/pretty_inspect'
|
30
|
+
autoload :KeyConversion, 'hashie/extensions/key_conversion'
|
31
31
|
autoload :MethodAccessWithOverride, 'hashie/extensions/method_access'
|
32
|
-
autoload :StrictKeyAccess,
|
33
|
-
autoload :RubyVersion,
|
34
|
-
autoload :RubyVersionCheck,
|
32
|
+
autoload :StrictKeyAccess, 'hashie/extensions/strict_key_access'
|
33
|
+
autoload :RubyVersion, 'hashie/extensions/ruby_version'
|
34
|
+
autoload :RubyVersionCheck, 'hashie/extensions/ruby_version_check'
|
35
35
|
|
36
36
|
module Parsers
|
37
37
|
autoload :YamlErbParser, 'hashie/extensions/parsers/yaml_erb_parser'
|
@@ -41,12 +41,15 @@ module Hashie
|
|
41
41
|
autoload :IndifferentAccess, 'hashie/extensions/dash/indifferent_access'
|
42
42
|
autoload :PropertyTranslation, 'hashie/extensions/dash/property_translation'
|
43
43
|
autoload :Coercion, 'hashie/extensions/dash/coercion'
|
44
|
+
autoload :PredefinedValues, 'hashie/extensions/dash/predefined_values'
|
44
45
|
end
|
45
46
|
|
46
47
|
module Mash
|
47
48
|
autoload :KeepOriginalKeys, 'hashie/extensions/mash/keep_original_keys'
|
49
|
+
autoload :PermissiveRespondTo, 'hashie/extensions/mash/permissive_respond_to'
|
48
50
|
autoload :SafeAssignment, 'hashie/extensions/mash/safe_assignment'
|
49
51
|
autoload :SymbolizeKeys, 'hashie/extensions/mash/symbolize_keys'
|
52
|
+
autoload :DefineAccessors, 'hashie/extensions/mash/define_accessors'
|
50
53
|
end
|
51
54
|
|
52
55
|
module Array
|
metadata
CHANGED
@@ -1,58 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
- Jerry Cheung
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: rspec
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '3.0'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '3.0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rspec-pending_for
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - "~>"
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0.1'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0.1'
|
27
|
+
version: '0'
|
56
28
|
description: Hashie is a collection of classes and mixins that make hashes more powerful.
|
57
29
|
email:
|
58
30
|
- michael@intridea.com
|
@@ -73,10 +45,12 @@ files:
|
|
73
45
|
- lib/hashie/array.rb
|
74
46
|
- lib/hashie/clash.rb
|
75
47
|
- lib/hashie/dash.rb
|
48
|
+
- lib/hashie/extensions/active_support/core_ext/hash.rb
|
76
49
|
- lib/hashie/extensions/array/pretty_inspect.rb
|
77
50
|
- lib/hashie/extensions/coercion.rb
|
78
51
|
- lib/hashie/extensions/dash/coercion.rb
|
79
52
|
- lib/hashie/extensions/dash/indifferent_access.rb
|
53
|
+
- lib/hashie/extensions/dash/predefined_values.rb
|
80
54
|
- lib/hashie/extensions/dash/property_translation.rb
|
81
55
|
- lib/hashie/extensions/deep_fetch.rb
|
82
56
|
- lib/hashie/extensions/deep_find.rb
|
@@ -84,8 +58,11 @@ files:
|
|
84
58
|
- lib/hashie/extensions/deep_merge.rb
|
85
59
|
- lib/hashie/extensions/ignore_undeclared.rb
|
86
60
|
- lib/hashie/extensions/indifferent_access.rb
|
61
|
+
- lib/hashie/extensions/key_conflict_warning.rb
|
87
62
|
- lib/hashie/extensions/key_conversion.rb
|
63
|
+
- lib/hashie/extensions/mash/define_accessors.rb
|
88
64
|
- lib/hashie/extensions/mash/keep_original_keys.rb
|
65
|
+
- lib/hashie/extensions/mash/permissive_respond_to.rb
|
89
66
|
- lib/hashie/extensions/mash/safe_assignment.rb
|
90
67
|
- lib/hashie/extensions/mash/symbolize_keys.rb
|
91
68
|
- lib/hashie/extensions/merge_initializer.rb
|
@@ -105,56 +82,15 @@ files:
|
|
105
82
|
- lib/hashie/trash.rb
|
106
83
|
- lib/hashie/utils.rb
|
107
84
|
- lib/hashie/version.rb
|
108
|
-
|
109
|
-
- spec/hashie/clash_spec.rb
|
110
|
-
- spec/hashie/dash_spec.rb
|
111
|
-
- spec/hashie/extensions/autoload_spec.rb
|
112
|
-
- spec/hashie/extensions/coercion_spec.rb
|
113
|
-
- spec/hashie/extensions/dash/coercion_spec.rb
|
114
|
-
- spec/hashie/extensions/dash/indifferent_access_spec.rb
|
115
|
-
- spec/hashie/extensions/deep_fetch_spec.rb
|
116
|
-
- spec/hashie/extensions/deep_find_spec.rb
|
117
|
-
- spec/hashie/extensions/deep_locate_spec.rb
|
118
|
-
- spec/hashie/extensions/deep_merge_spec.rb
|
119
|
-
- spec/hashie/extensions/ignore_undeclared_spec.rb
|
120
|
-
- spec/hashie/extensions/indifferent_access_spec.rb
|
121
|
-
- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
|
122
|
-
- spec/hashie/extensions/key_conversion_spec.rb
|
123
|
-
- spec/hashie/extensions/mash/keep_original_keys_spec.rb
|
124
|
-
- spec/hashie/extensions/mash/safe_assignment_spec.rb
|
125
|
-
- spec/hashie/extensions/mash/symbolize_keys_spec.rb
|
126
|
-
- spec/hashie/extensions/merge_initializer_spec.rb
|
127
|
-
- spec/hashie/extensions/method_access_spec.rb
|
128
|
-
- spec/hashie/extensions/strict_key_access_spec.rb
|
129
|
-
- spec/hashie/extensions/stringify_keys_spec.rb
|
130
|
-
- spec/hashie/extensions/symbolize_keys_spec.rb
|
131
|
-
- spec/hashie/hash_spec.rb
|
132
|
-
- spec/hashie/mash_spec.rb
|
133
|
-
- spec/hashie/parsers/yaml_erb_parser_spec.rb
|
134
|
-
- spec/hashie/rash_spec.rb
|
135
|
-
- spec/hashie/trash_spec.rb
|
136
|
-
- spec/hashie/utils_spec.rb
|
137
|
-
- spec/hashie/version_spec.rb
|
138
|
-
- spec/hashie_spec.rb
|
139
|
-
- spec/integration/elasticsearch/integration_spec.rb
|
140
|
-
- spec/integration/omniauth-oauth2/app.rb
|
141
|
-
- spec/integration/omniauth-oauth2/integration_spec.rb
|
142
|
-
- spec/integration/omniauth-oauth2/some_site.rb
|
143
|
-
- spec/integration/omniauth/app.rb
|
144
|
-
- spec/integration/omniauth/integration_spec.rb
|
145
|
-
- spec/integration/rails-without-dependency/integration_spec.rb
|
146
|
-
- spec/integration/rails/app.rb
|
147
|
-
- spec/integration/rails/integration_spec.rb
|
148
|
-
- spec/spec_helper.rb
|
149
|
-
- spec/support/integration_specs.rb
|
150
|
-
- spec/support/logger.rb
|
151
|
-
- spec/support/module_context.rb
|
152
|
-
- spec/support/ruby_version_check.rb
|
153
|
-
homepage: https://github.com/intridea/hashie
|
85
|
+
homepage: https://github.com/hashie/hashie
|
154
86
|
licenses:
|
155
87
|
- MIT
|
156
|
-
metadata:
|
157
|
-
|
88
|
+
metadata:
|
89
|
+
bug_tracker_uri: https://github.com/hashie/hashie/issues
|
90
|
+
changelog_uri: https://github.com/hashie/hashie/blob/master/CHANGELOG.md
|
91
|
+
documentation_uri: https://www.rubydoc.info/gems/hashie
|
92
|
+
source_code_uri: https://github.com/hashie/hashie
|
93
|
+
post_install_message:
|
158
94
|
rdoc_options: []
|
159
95
|
require_paths:
|
160
96
|
- lib
|
@@ -169,54 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
105
|
- !ruby/object:Gem::Version
|
170
106
|
version: '0'
|
171
107
|
requirements: []
|
172
|
-
|
173
|
-
|
174
|
-
signing_key:
|
108
|
+
rubygems_version: 3.1.3
|
109
|
+
signing_key:
|
175
110
|
specification_version: 4
|
176
111
|
summary: Your friendly neighborhood hash library.
|
177
|
-
test_files:
|
178
|
-
- spec/hashie/parsers/yaml_erb_parser_spec.rb
|
179
|
-
- spec/hashie/array_spec.rb
|
180
|
-
- spec/hashie/hash_spec.rb
|
181
|
-
- spec/hashie/version_spec.rb
|
182
|
-
- spec/hashie/clash_spec.rb
|
183
|
-
- spec/hashie/mash_spec.rb
|
184
|
-
- spec/hashie/extensions/stringify_keys_spec.rb
|
185
|
-
- spec/hashie/extensions/deep_locate_spec.rb
|
186
|
-
- spec/hashie/extensions/coercion_spec.rb
|
187
|
-
- spec/hashie/extensions/mash/safe_assignment_spec.rb
|
188
|
-
- spec/hashie/extensions/mash/symbolize_keys_spec.rb
|
189
|
-
- spec/hashie/extensions/mash/keep_original_keys_spec.rb
|
190
|
-
- spec/hashie/extensions/key_conversion_spec.rb
|
191
|
-
- spec/hashie/extensions/ignore_undeclared_spec.rb
|
192
|
-
- spec/hashie/extensions/autoload_spec.rb
|
193
|
-
- spec/hashie/extensions/strict_key_access_spec.rb
|
194
|
-
- spec/hashie/extensions/deep_fetch_spec.rb
|
195
|
-
- spec/hashie/extensions/method_access_spec.rb
|
196
|
-
- spec/hashie/extensions/deep_find_spec.rb
|
197
|
-
- spec/hashie/extensions/deep_merge_spec.rb
|
198
|
-
- spec/hashie/extensions/merge_initializer_spec.rb
|
199
|
-
- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb
|
200
|
-
- spec/hashie/extensions/dash/coercion_spec.rb
|
201
|
-
- spec/hashie/extensions/dash/indifferent_access_spec.rb
|
202
|
-
- spec/hashie/extensions/symbolize_keys_spec.rb
|
203
|
-
- spec/hashie/extensions/indifferent_access_spec.rb
|
204
|
-
- spec/hashie/rash_spec.rb
|
205
|
-
- spec/hashie/utils_spec.rb
|
206
|
-
- spec/hashie/dash_spec.rb
|
207
|
-
- spec/hashie/trash_spec.rb
|
208
|
-
- spec/spec_helper.rb
|
209
|
-
- spec/integration/rails-without-dependency/integration_spec.rb
|
210
|
-
- spec/integration/omniauth-oauth2/integration_spec.rb
|
211
|
-
- spec/integration/omniauth-oauth2/app.rb
|
212
|
-
- spec/integration/omniauth-oauth2/some_site.rb
|
213
|
-
- spec/integration/omniauth/integration_spec.rb
|
214
|
-
- spec/integration/omniauth/app.rb
|
215
|
-
- spec/integration/elasticsearch/integration_spec.rb
|
216
|
-
- spec/integration/rails/integration_spec.rb
|
217
|
-
- spec/integration/rails/app.rb
|
218
|
-
- spec/support/module_context.rb
|
219
|
-
- spec/support/logger.rb
|
220
|
-
- spec/support/integration_specs.rb
|
221
|
-
- spec/support/ruby_version_check.rb
|
222
|
-
- spec/hashie_spec.rb
|
112
|
+
test_files: []
|
data/spec/hashie/array_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Array do
|
4
|
-
with_minimum_ruby('2.3.0') do
|
5
|
-
describe '#dig' do
|
6
|
-
let(:array) { Hashie::Array.new(%i[a b c]) }
|
7
|
-
|
8
|
-
it 'works with a string index' do
|
9
|
-
expect(array.dig('0')).to eq(:a)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'works with a numeric index' do
|
13
|
-
expect(array.dig(1)).to eq(:b)
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when array is empty' do
|
17
|
-
let(:array) { Hashie::Array.new([]) }
|
18
|
-
|
19
|
-
it 'works with a first numeric and next string index' do
|
20
|
-
expect(array.dig(0, 'hello')).to eq(nil)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'throws an error with first string and next numeric index' do
|
24
|
-
expect { array.dig('hello', 0) }.to raise_error(TypeError)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|