hashie 3.5.7 → 3.6.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 +5 -5
- data/CHANGELOG.md +22 -0
- data/README.md +91 -22
- data/Rakefile +2 -2
- data/hashie.gemspec +1 -1
- data/lib/hashie/clash.rb +12 -1
- data/lib/hashie/dash.rb +41 -21
- data/lib/hashie/extensions/coercion.rb +5 -5
- data/lib/hashie/extensions/dash/property_translation.rb +49 -26
- data/lib/hashie/extensions/deep_fetch.rb +1 -1
- data/lib/hashie/extensions/deep_find.rb +2 -2
- data/lib/hashie/extensions/deep_locate.rb +4 -5
- data/lib/hashie/extensions/deep_merge.rb +8 -9
- data/lib/hashie/extensions/indifferent_access.rb +7 -5
- data/lib/hashie/extensions/mash/keep_original_keys.rb +3 -5
- data/lib/hashie/extensions/mash/safe_assignment.rb +1 -1
- data/lib/hashie/extensions/mash/symbolize_keys.rb +1 -1
- data/lib/hashie/extensions/method_access.rb +47 -17
- data/lib/hashie/extensions/parsers/yaml_erb_parser.rb +3 -1
- data/lib/hashie/extensions/strict_key_access.rb +8 -9
- data/lib/hashie/extensions/stringify_keys.rb +1 -1
- data/lib/hashie/extensions/symbolize_keys.rb +1 -1
- data/lib/hashie/hash.rb +4 -4
- data/lib/hashie/mash.rb +22 -22
- data/lib/hashie/rash.rb +5 -5
- data/lib/hashie/version.rb +1 -1
- data/spec/hashie/array_spec.rb +1 -1
- data/spec/hashie/dash_spec.rb +27 -2
- data/spec/hashie/extensions/coercion_spec.rb +20 -12
- data/spec/hashie/extensions/deep_locate_spec.rb +1 -1
- data/spec/hashie/extensions/deep_merge_spec.rb +1 -1
- data/spec/hashie/extensions/indifferent_access_spec.rb +20 -7
- data/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +5 -5
- data/spec/hashie/extensions/method_access_spec.rb +42 -4
- data/spec/hashie/extensions/stringify_keys_spec.rb +4 -4
- data/spec/hashie/extensions/symbolize_keys_spec.rb +3 -3
- data/spec/hashie/mash_spec.rb +16 -8
- data/spec/hashie/parsers/yaml_erb_parser_spec.rb +3 -3
- data/spec/hashie/rash_spec.rb +2 -2
- data/spec/hashie/trash_spec.rb +61 -1
- data/spec/integration/elasticsearch/integration_spec.rb +40 -0
- data/spec/integration/omniauth-oauth2/app.rb +3 -4
- data/spec/integration/omniauth-oauth2/some_site.rb +2 -2
- data/spec/integration/rails/app.rb +3 -4
- metadata +5 -3
data/spec/hashie/mash_spec.rb
CHANGED
@@ -184,7 +184,8 @@ describe Hashie::Mash do
|
|
184
184
|
details: {
|
185
185
|
email: 'michael@asf.com',
|
186
186
|
address: 'Nowhere road'
|
187
|
-
}
|
187
|
+
}
|
188
|
+
)
|
188
189
|
end
|
189
190
|
|
190
191
|
describe '#deep_update' do
|
@@ -284,7 +285,7 @@ describe Hashie::Mash do
|
|
284
285
|
end
|
285
286
|
|
286
287
|
it 'leaves only specified keys' do
|
287
|
-
expect(subject.keys.sort).to eq %w
|
288
|
+
expect(subject.keys.sort).to eq %w[details middle_name]
|
288
289
|
expect(subject.first_name?).to be_falsy
|
289
290
|
expect(subject).not_to respond_to(:first_name)
|
290
291
|
expect(subject.last_name?).to be_falsy
|
@@ -386,28 +387,28 @@ describe Hashie::Mash do
|
|
386
387
|
end
|
387
388
|
|
388
389
|
it 'responds to a set key with a suffix' do
|
389
|
-
%w
|
390
|
+
%w[= ? ! _].each do |suffix|
|
390
391
|
expect(subject).to be_respond_to(:"abc#{suffix}")
|
391
392
|
end
|
392
393
|
end
|
393
394
|
|
394
395
|
it 'is able to access the suffixed key as a method' do
|
395
|
-
%w
|
396
|
+
%w[= ? ! _].each do |suffix|
|
396
397
|
expect(subject.method(:"abc#{suffix}")).to_not be_nil
|
397
398
|
end
|
398
399
|
end
|
399
400
|
|
400
401
|
it 'responds to an unknown key with a suffix' do
|
401
|
-
%w
|
402
|
+
%w[= ? ! _].each do |suffix|
|
402
403
|
expect(subject).to be_respond_to(:"xyz#{suffix}")
|
403
404
|
end
|
404
405
|
end
|
405
406
|
|
406
407
|
it 'is able to access an unknown suffixed key as a method' do
|
407
408
|
# See https://github.com/intridea/hashie/pull/285 for more information
|
408
|
-
pending_for(engine: 'ruby', versions: %w
|
409
|
+
pending_for(engine: 'ruby', versions: %w[2.2.0 2.2.1 2.2.2])
|
409
410
|
|
410
|
-
%w
|
411
|
+
%w[= ? ! _].each do |suffix|
|
411
412
|
expect(subject.method(:"xyz#{suffix}")).to_not be_nil
|
412
413
|
end
|
413
414
|
end
|
@@ -457,6 +458,13 @@ describe Hashie::Mash do
|
|
457
458
|
expect(initial.test?).to be_truthy
|
458
459
|
end
|
459
460
|
|
461
|
+
it 'allows propagation of a default block' do
|
462
|
+
h = Hashie::Mash.new { |mash, key| mash[key] = mash.class.new(&mash.default_proc) }
|
463
|
+
expect { h[:x][:y][:z] = :xyz }.not_to raise_error
|
464
|
+
expect(h.x.y.z).to eq(:xyz)
|
465
|
+
expect(h[:x][:y][:z]).to eq(:xyz)
|
466
|
+
end
|
467
|
+
|
460
468
|
it 'allows assignment of an empty array in a default block' do
|
461
469
|
initial = Hashie::Mash.new { |h, k| h[k] = [] }
|
462
470
|
initial.hello << 100
|
@@ -553,7 +561,7 @@ describe Hashie::Mash do
|
|
553
561
|
end
|
554
562
|
|
555
563
|
it 'includes all keys' do
|
556
|
-
expect(mash.to_hash.keys).to eql(%w
|
564
|
+
expect(mash.to_hash.keys).to eql(%w[outer testing])
|
557
565
|
end
|
558
566
|
|
559
567
|
it 'converts keys to symbols when symbolize_keys option is true' do
|
@@ -4,12 +4,12 @@ describe Hashie::Extensions::Parsers::YamlErbParser do
|
|
4
4
|
describe '.perform' do
|
5
5
|
context 'a file' do
|
6
6
|
let(:config) do
|
7
|
-
<<-
|
7
|
+
<<-CONFIG
|
8
8
|
---
|
9
9
|
foo: verbatim
|
10
10
|
bar: <%= "erb" %>
|
11
11
|
baz: "<%= __FILE__ %>"
|
12
|
-
|
12
|
+
CONFIG
|
13
13
|
end
|
14
14
|
let(:path) { 'template.yml' }
|
15
15
|
|
@@ -36,7 +36,7 @@ baz: "<%= __FILE__ %>"
|
|
36
36
|
file
|
37
37
|
end
|
38
38
|
|
39
|
-
subject { described_class.new(Pathname
|
39
|
+
subject { described_class.new(Pathname(tempfile.path)) }
|
40
40
|
|
41
41
|
it '"#perform" can be done in case of path is a Pathname object.' do
|
42
42
|
expect(subject.perform).to eq 'foo' => 'hello'
|
data/spec/hashie/rash_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Hashie::Rash do
|
|
10
10
|
1 => 'awesome',
|
11
11
|
1..1000 => 'rangey',
|
12
12
|
/(bcd)/ => proc { |m| m[1] }
|
13
|
-
|
13
|
+
# /.+/ => "EVERYTHING"
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
@@ -18,7 +18,7 @@ describe Hashie::Rash do
|
|
18
18
|
expect(subject['other']).to eq 'whee'
|
19
19
|
expect(subject['well hello there']).to eq 'hello'
|
20
20
|
expect(subject['the world is round']).to eq 'world'
|
21
|
-
expect(subject.all('hello world').sort).to eq %w
|
21
|
+
expect(subject.all('hello world').sort).to eq %w[hello world]
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'finds regexps' do
|
data/spec/hashie/trash_spec.rb
CHANGED
@@ -153,7 +153,7 @@ describe Hashie::Trash do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'maintains translations hash mapping from the original to the translated name' do
|
156
|
-
expect(SomeDataModel.translations).to eq(config: [
|
156
|
+
expect(SomeDataModel.translations).to eq(config: %i[value_a value_b])
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
@@ -265,4 +265,64 @@ describe Hashie::Trash do
|
|
265
265
|
expect(subject.first_name).to eq('Frodo')
|
266
266
|
end
|
267
267
|
end
|
268
|
+
|
269
|
+
context 'when copying properties from other properties' do
|
270
|
+
it 'retains the original and also sets the copy' do
|
271
|
+
simple = Class.new(Hashie::Trash) do
|
272
|
+
property :id
|
273
|
+
property :copy_of_id, from: :id
|
274
|
+
end
|
275
|
+
|
276
|
+
subject = simple.new(id: 1)
|
277
|
+
|
278
|
+
expect(subject.id).to eq(1)
|
279
|
+
expect(subject.copy_of_id).to eq(1)
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'grabs the default for the original if it is not set' do
|
283
|
+
with_default = Class.new(Hashie::Trash) do
|
284
|
+
property :id, default: 0
|
285
|
+
property :copy_of_id, from: :id
|
286
|
+
end
|
287
|
+
|
288
|
+
subject = with_default.new
|
289
|
+
|
290
|
+
expect(subject.id).to eq(0)
|
291
|
+
expect(subject.copy_of_id).to eq(0)
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'can be a required value' do
|
295
|
+
with_required = Class.new(Hashie::Trash) do
|
296
|
+
property :id
|
297
|
+
property :copy_of_id, from: :id, required: true, message: 'must be set'
|
298
|
+
end
|
299
|
+
|
300
|
+
expect { with_required.new }.to raise_error(ArgumentError, "The property 'copy_of_id' must be set")
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'does not set properties that do not exist' do
|
304
|
+
from_non_property = Class.new(Hashie::Trash) do
|
305
|
+
property :copy_of_value, from: :value
|
306
|
+
end
|
307
|
+
|
308
|
+
subject = from_non_property.new(value: 0)
|
309
|
+
|
310
|
+
expect(subject).not_to respond_to(:value)
|
311
|
+
expect { subject[:value] }.to raise_error(NoMethodError, "The property 'value' is not defined for .")
|
312
|
+
expect(subject.to_h[:value]).to eq(nil)
|
313
|
+
expect(subject.copy_of_value).to eq(0)
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'is not order-dependent in definition' do
|
317
|
+
simple = Class.new(Hashie::Trash) do
|
318
|
+
property :copy_of_id, from: :id
|
319
|
+
property :id
|
320
|
+
end
|
321
|
+
|
322
|
+
subject = simple.new(id: 1)
|
323
|
+
|
324
|
+
expect(subject.id).to eq(1)
|
325
|
+
expect(subject.copy_of_id).to eq(1)
|
326
|
+
end
|
327
|
+
end
|
268
328
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'elasticsearch/model'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expect|
|
6
|
+
expect.syntax = :expect
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class MyModel < Hashie::Mash
|
11
|
+
include Elasticsearch::Model
|
12
|
+
|
13
|
+
disable_warnings
|
14
|
+
|
15
|
+
index_name 'model'
|
16
|
+
document_type 'model'
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.describe 'elaasticsearch-model' do
|
20
|
+
# See https://github.com/intridea/hashie/issues/354#issuecomment-363306114
|
21
|
+
# for the reason why this doesn't work as you would expect
|
22
|
+
it 'raises an error when the model does has an id' do
|
23
|
+
object = MyModel.new
|
24
|
+
stub_elasticsearch_client
|
25
|
+
|
26
|
+
expect { object.__elasticsearch__.index_document }.to raise_error(NoMethodError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'does not raise an error when the model has an id' do
|
30
|
+
object = MyModel.new(id: 123)
|
31
|
+
stub_elasticsearch_client
|
32
|
+
|
33
|
+
expect { object.__elasticsearch__.index_document }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
def stub_elasticsearch_client
|
37
|
+
response = double('Response', body: '{}')
|
38
|
+
allow_any_instance_of(Elasticsearch::Transport::Client).to receive(:perform_request) { response }
|
39
|
+
end
|
40
|
+
end
|
@@ -19,7 +19,7 @@ module RailsApp
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
LAYOUT = <<-HTML
|
22
|
+
LAYOUT = <<-HTML.freeze
|
23
23
|
<!DOCTYPE html>
|
24
24
|
<html>
|
25
25
|
<head>
|
@@ -32,7 +32,7 @@ LAYOUT = <<-HTML
|
|
32
32
|
</html>
|
33
33
|
HTML
|
34
34
|
|
35
|
-
INDEX = '<h1>Hello, world!</h1>'
|
35
|
+
INDEX = '<h1>Hello, world!</h1>'.freeze
|
36
36
|
|
37
37
|
class ApplicationController < ActionController::Base
|
38
38
|
include Rails.application.routes.url_helpers
|
@@ -44,8 +44,7 @@ class ApplicationController < ActionController::Base
|
|
44
44
|
'application/index.html.erb' => INDEX
|
45
45
|
)]
|
46
46
|
|
47
|
-
def index
|
48
|
-
end
|
47
|
+
def index; end
|
49
48
|
end
|
50
49
|
|
51
50
|
Bundler.require(:default, Rails.env)
|
@@ -14,7 +14,7 @@ module RailsApp
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
LAYOUT = <<-HTML
|
17
|
+
LAYOUT = <<-HTML.freeze
|
18
18
|
<!DOCTYPE html>
|
19
19
|
<html>
|
20
20
|
<head>
|
@@ -27,7 +27,7 @@ LAYOUT = <<-HTML
|
|
27
27
|
</html>
|
28
28
|
HTML
|
29
29
|
|
30
|
-
INDEX = '<h1>Hello, world!</h1>'
|
30
|
+
INDEX = '<h1>Hello, world!</h1>'.freeze
|
31
31
|
|
32
32
|
class ApplicationController < ActionController::Base
|
33
33
|
include Rails.application.routes.url_helpers
|
@@ -39,8 +39,7 @@ class ApplicationController < ActionController::Base
|
|
39
39
|
'application/index.html.erb' => INDEX
|
40
40
|
)]
|
41
41
|
|
42
|
-
def index
|
43
|
-
end
|
42
|
+
def index; end
|
44
43
|
end
|
45
44
|
|
46
45
|
Bundler.require(:default, Rails.env)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- spec/hashie/utils_spec.rb
|
137
137
|
- spec/hashie/version_spec.rb
|
138
138
|
- spec/hashie_spec.rb
|
139
|
+
- spec/integration/elasticsearch/integration_spec.rb
|
139
140
|
- spec/integration/omniauth-oauth2/app.rb
|
140
141
|
- spec/integration/omniauth-oauth2/integration_spec.rb
|
141
142
|
- spec/integration/omniauth-oauth2/some_site.rb
|
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
version: '0'
|
170
171
|
requirements: []
|
171
172
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6
|
173
|
+
rubygems_version: 2.7.6
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: Your friendly neighborhood hash library.
|
@@ -211,6 +212,7 @@ test_files:
|
|
211
212
|
- spec/integration/omniauth-oauth2/some_site.rb
|
212
213
|
- spec/integration/omniauth/integration_spec.rb
|
213
214
|
- spec/integration/omniauth/app.rb
|
215
|
+
- spec/integration/elasticsearch/integration_spec.rb
|
214
216
|
- spec/integration/rails/integration_spec.rb
|
215
217
|
- spec/integration/rails/app.rb
|
216
218
|
- spec/support/module_context.rb
|