hashie 2.1.2 → 3.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.
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Hash do
4
4
  it 'is convertible to a Hashie::Mash' do
5
5
  mash = Hashie::Hash[some: 'hash'].to_mash
6
- expect(mash.is_a?(Hashie::Mash)).to be true
6
+ expect(mash.is_a?(Hashie::Mash)).to be_truthy
7
7
  expect(mash.some).to eq 'hash'
8
8
  end
9
9
 
@@ -13,6 +13,12 @@ describe Hash do
13
13
  expect(hash).to eq Hashie::Hash['a' => 'hey', '123' => 'bob']
14
14
  end
15
15
 
16
+ it '#stringify_keys! turns all keys into strings non-recursively' do
17
+ hash = Hashie::Hash[:a => 'hey', 123 => { 345 => 'hey' }]
18
+ hash.stringify_keys!
19
+ expect(hash).to eq Hashie::Hash['a' => 'hey', '123' => { 345 => 'hey' }]
20
+ end
21
+
16
22
  it '#stringify_keys returns a hash with stringified keys' do
17
23
  hash = Hashie::Hash[:a => 'hey', 123 => 'bob']
18
24
  stringified_hash = hash.stringify_keys
@@ -20,10 +26,16 @@ describe Hash do
20
26
  expect(stringified_hash).to eq Hashie::Hash['a' => 'hey', '123' => 'bob']
21
27
  end
22
28
 
23
- it '#to_hash returns a hash with stringified keys' do
29
+ it '#to_hash returns a hash with same keys' do
24
30
  hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3]]
25
31
  stringified_hash = hash.to_hash
26
- expect(stringified_hash).to eq('a' => 'hey', '123' => 'bob', 'array' => [1, 2, 3])
32
+ expect(stringified_hash).to eq('a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3])
33
+ end
34
+
35
+ it '#to_hash with stringify_keys set to true returns a hash with stringified_keys' do
36
+ hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3]]
37
+ symbolized_hash = hash.to_hash(stringify_keys: true)
38
+ expect(symbolized_hash).to eq('a' => 'hey', '123' => 'bob', 'array' => [1, 2, 3])
27
39
  end
28
40
 
29
41
  it '#to_hash with symbolize_keys set to true returns a hash with symbolized keys' do
@@ -43,24 +55,4 @@ describe Hash do
43
55
  h[:key] = BareCustomMash.new
44
56
  expect { h.to_hash }.not_to raise_error
45
57
  end
46
-
47
- describe 'when the value is an object that respond_to to_hash' do
48
- class ClassRespondsToHash
49
- def to_hash(options = {})
50
- Hashie::Hash['a' => 'hey', b: 'bar', 123 => 'bob', 'array' => [1, 2, 3]].to_hash(options)
51
- end
52
- end
53
-
54
- it '#to_hash with stringify_keys set to true returns a hash with stringified_keys' do
55
- hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3], subhash: ClassRespondsToHash.new]
56
- symbolized_hash = hash.to_hash(stringify_keys: true)
57
- expect(symbolized_hash).to eq('a' => 'hey', '123' => 'bob', 'array' => [1, 2, 3], 'subhash' => { 'a' => 'hey', 'b' => 'bar', '123' => 'bob', 'array' => [1, 2, 3] })
58
- end
59
-
60
- it '#to_hash with symbolize_keys set to true returns a hash with symbolized keys' do
61
- hash = Hashie::Hash['a' => 'hey', 123 => 'bob', 'array' => [1, 2, 3], subhash: ClassRespondsToHash.new]
62
- symbolized_hash = hash.to_hash(symbolize_keys: true)
63
- expect(symbolized_hash).to eq(:a => 'hey', :"123" => 'bob', :array => [1, 2, 3], subhash: { :a => 'hey', :b => 'bar', :'123' => 'bob', :array => [1, 2, 3] })
64
- end
65
- end
66
58
  end
@@ -5,7 +5,7 @@ describe Hashie::Mash do
5
5
  subject { Hashie::Mash.new }
6
6
 
7
7
  it 'inherits from Hash' do
8
- expect(subject.is_a?(Hash)).to be true
8
+ expect(subject.is_a?(Hash)).to be_truthy
9
9
  end
10
10
 
11
11
  it 'sets hash values through method= calls' do
@@ -33,9 +33,9 @@ describe Hashie::Mash do
33
33
  end
34
34
 
35
35
  it 'tests for already set values when passed a ? method' do
36
- expect(subject.test?).to be false
36
+ expect(subject.test?).to be_falsy
37
37
  subject.test = 'abc'
38
- expect(subject.test?).to be true
38
+ expect(subject.test?).to be_truthy
39
39
  end
40
40
 
41
41
  it 'returns false on a ? method if a value has been set to nil or false' do
@@ -47,7 +47,7 @@ describe Hashie::Mash do
47
47
 
48
48
  it 'makes all [] and []= into strings for consistency' do
49
49
  subject['abc'] = 123
50
- expect(subject.key?('abc')).to be true
50
+ expect(subject.key?('abc')).to be_truthy
51
51
  expect(subject['abc']).to eq 123
52
52
  end
53
53
 
@@ -72,7 +72,7 @@ describe Hashie::Mash do
72
72
  end
73
73
 
74
74
  it 'returns a Hashie::Mash when passed a bang method to a non-existenct key' do
75
- expect(subject.abc!.is_a?(Hashie::Mash)).to be true
75
+ expect(subject.abc!.is_a?(Hashie::Mash)).to be_truthy
76
76
  end
77
77
 
78
78
  it 'returns the existing value when passed a bang method for an existing key' do
@@ -81,7 +81,7 @@ describe Hashie::Mash do
81
81
  end
82
82
 
83
83
  it 'returns a Hashie::Mash when passed an under bang method to a non-existenct key' do
84
- expect(subject.abc_.is_a?(Hashie::Mash)).to be true
84
+ expect(subject.abc_.is_a?(Hashie::Mash)).to be_truthy
85
85
  end
86
86
 
87
87
  it 'returns the existing value when passed an under bang method for an existing key' do
@@ -90,7 +90,7 @@ describe Hashie::Mash do
90
90
  end
91
91
 
92
92
  it '#initializing_reader returns a Hashie::Mash when passed a non-existent key' do
93
- expect(subject.initializing_reader(:abc).is_a?(Hashie::Mash)).to be true
93
+ expect(subject.initializing_reader(:abc).is_a?(Hashie::Mash)).to be_truthy
94
94
  end
95
95
 
96
96
  it 'allows for multi-level assignment through bang methods' do
@@ -176,7 +176,7 @@ describe Hashie::Mash do
176
176
 
177
177
  # http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-update
178
178
  it 'accepts a block' do
179
- duped = subject.merge(details: { address: 'Pasadena CA' }) { |key, oldv, newv| [oldv, newv].join(', ') }
179
+ duped = subject.merge(details: { address: 'Pasadena CA' }) { |_, oldv, newv| [oldv, newv].join(', ') }
180
180
  expect(duped.details.address).to eq 'Nowhere road, Pasadena CA'
181
181
  end
182
182
  end
@@ -218,18 +218,18 @@ describe Hashie::Mash do
218
218
  end
219
219
 
220
220
  it 'sets all specified keys to their corresponding values' do
221
- expect(subject.middle_name?).to be true
222
- expect(subject.details?).to be true
221
+ expect(subject.middle_name?).to be_truthy
222
+ expect(subject.details?).to be_truthy
223
223
  expect(subject.middle_name).to eq 'Cain'
224
- expect(subject.details.city?).to be true
224
+ expect(subject.details.city?).to be_truthy
225
225
  expect(subject.details.city).to eq 'Imagination'
226
226
  end
227
227
 
228
228
  it 'leaves only specified keys' do
229
229
  expect(subject.keys.sort).to eq %w(details middle_name)
230
- expect(subject.first_name?).to be false
230
+ expect(subject.first_name?).to be_falsy
231
231
  expect(subject).not_to respond_to(:first_name)
232
- expect(subject.last_name?).to be false
232
+ expect(subject.last_name?).to be_falsy
233
233
  expect(subject).not_to respond_to(:last_name)
234
234
  end
235
235
  end
@@ -314,32 +314,36 @@ describe Hashie::Mash do
314
314
  end
315
315
 
316
316
  describe '#respond_to?' do
317
+ subject do
318
+ Hashie::Mash.new(abc: 'def')
319
+ end
320
+
317
321
  it 'responds to a normal method' do
318
- expect(Hashie::Mash.new).to be_respond_to(:key?)
322
+ expect(subject).to be_respond_to(:key?)
319
323
  end
320
324
 
321
325
  it 'responds to a set key' do
322
- expect(Hashie::Mash.new(abc: 'def')).to be_respond_to(:abc)
326
+ expect(subject).to be_respond_to(:abc)
327
+ expect(subject.method(:abc)).to_not be_nil
323
328
  end
324
329
 
325
330
  it 'responds to a set key with a suffix' do
326
331
  %w(= ? ! _).each do |suffix|
327
- expect(Hashie::Mash.new(abc: 'def')).to be_respond_to(:"abc#{suffix}")
332
+ expect(subject).to be_respond_to(:"abc#{suffix}")
333
+ expect(subject.method(:"abc#{suffix}")).to_not be_nil
328
334
  end
329
335
  end
330
336
 
331
- it 'does not respond to an unknown key with a suffix' do
337
+ it 'responds to an unknown key with a suffix' do
332
338
  %w(= ? ! _).each do |suffix|
333
- expect(Hashie::Mash.new(abc: 'def')).not_to be_respond_to(:"xyz#{suffix}")
339
+ expect(subject).to be_respond_to(:"xyz#{suffix}")
340
+ expect(subject.method(:"xyz#{suffix}")).to_not be_nil
334
341
  end
335
342
  end
336
343
 
337
344
  it 'does not respond to an unknown key without a suffix' do
338
- expect(Hashie::Mash.new(abc: 'def')).not_to be_respond_to(:xyz)
339
- end
340
-
341
- it 'does not respond to permitted?' do
342
- expect(Hashie::Mash.new).not_to be_respond_to(:permitted?)
345
+ expect(subject).not_to be_respond_to(:xyz)
346
+ expect { subject.method(:xyz) }.to raise_error(NameError)
343
347
  end
344
348
  end
345
349
 
@@ -352,7 +356,7 @@ describe Hashie::Mash do
352
356
 
353
357
  it 'converts hashes recursively into Hashie::Mashes' do
354
358
  converted = Hashie::Mash.new(a: { b: 1, c: { d: 23 } })
355
- expect(converted.a.is_a?(Hashie::Mash)).to be true
359
+ expect(converted.a.is_a?(Hashie::Mash)).to be_truthy
356
360
  expect(converted.a.b).to eq 1
357
361
  expect(converted.a.c.d).to eq 23
358
362
  end
@@ -379,15 +383,15 @@ describe Hashie::Mash do
379
383
  expect(initial.default_proc).not_to be_nil
380
384
  expect(initial.default).to be_nil
381
385
  expect(initial.test).to eq []
382
- expect(initial.test?).to be true
386
+ expect(initial.test?).to be_truthy
383
387
  end
384
388
 
385
389
  it 'converts Hashie::Mashes within Arrays back to Hashes' do
386
390
  initial_hash = { 'a' => [{ 'b' => 12, 'c' => ['d' => 50, 'e' => 51] }, 23] }
387
391
  converted = Hashie::Mash.new(initial_hash)
388
- expect(converted.to_hash['a'].first.is_a?(Hashie::Mash)).to be false
389
- expect(converted.to_hash['a'].first.is_a?(Hash)).to be true
390
- expect(converted.to_hash['a'].first['c'].first.is_a?(Hashie::Mash)).to be false
392
+ expect(converted.to_hash['a'].first.is_a?(Hashie::Mash)).to be_falsy
393
+ expect(converted.to_hash['a'].first.is_a?(Hash)).to be_truthy
394
+ expect(converted.to_hash['a'].first['c'].first.is_a?(Hashie::Mash)).to be_falsy
391
395
  end
392
396
  end
393
397
 
@@ -429,7 +433,7 @@ describe Hashie::Mash do
429
433
 
430
434
  context 'with block given' do
431
435
  it 'returns default value' do
432
- expect(mash.fetch(:two) do |key|
436
+ expect(mash.fetch(:two) do
433
437
  'block default value'
434
438
  end).to eql('block default value')
435
439
  end
@@ -464,4 +468,12 @@ describe Hashie::Mash do
464
468
  expect(mash.to_hash(symbolize_keys: true)[:outer].keys).not_to include('inner')
465
469
  end
466
470
  end
471
+
472
+ describe '#stringify_keys' do
473
+ it 'turns all keys into strings recursively' do
474
+ hash = Hashie::Mash[:a => 'hey', 123 => { 345 => 'hey' }]
475
+ hash.stringify_keys!
476
+ expect(hash).to eq Hashie::Hash['a' => 'hey', '123' => { '345' => 'hey' }]
477
+ end
478
+ end
467
479
  end
@@ -57,11 +57,14 @@ describe Hashie::Trash do
57
57
  end
58
58
 
59
59
  it 'writes to an existing property using []=' do
60
- expect { trash['first_name'] = 'Bob' }.not_to raise_error
60
+ expect { trash[:first_name] = 'Bob' }.not_to raise_error
61
+ expect(trash.first_name).to eq('Bob')
62
+ expect { trash['first_name'] = 'John' }.to raise_error(NoMethodError)
61
63
  end
62
64
 
63
65
  it 'writes to a translated property using []=' do
64
- expect { trash['firstName'] = 'Bob' }.not_to raise_error
66
+ expect { trash[:firstName] = 'Bob' }.not_to raise_error
67
+ expect { trash['firstName'] = 'Bob' }.to raise_error(NoMethodError)
65
68
  end
66
69
 
67
70
  it 'reads/writes to an existing property using a method call' do
@@ -5,4 +5,3 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
 
6
6
  require 'hashie'
7
7
  require 'rspec'
8
- require 'rspec/autorun'
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Bleigh
@@ -10,40 +9,36 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-06-12 00:00:00.000000000 Z
12
+ date: 2014-06-03 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rspec
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ~>
37
33
  - !ruby/object:Gem::Version
38
- version: '0'
34
+ version: '3.0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - ~>
45
40
  - !ruby/object:Gem::Version
46
- version: '0'
41
+ version: '3.0'
47
42
  description: Hashie is a collection of classes and mixins that make hashes more powerful.
48
43
  email:
49
44
  - michael@intridea.com
@@ -64,11 +59,13 @@ files:
64
59
  - LICENSE
65
60
  - README.md
66
61
  - Rakefile
62
+ - UPGRADING.md
67
63
  - hashie.gemspec
68
64
  - lib/hashie.rb
69
65
  - lib/hashie/clash.rb
70
66
  - lib/hashie/dash.rb
71
67
  - lib/hashie/extensions/coercion.rb
68
+ - lib/hashie/extensions/dash/indifferent_access.rb
72
69
  - lib/hashie/extensions/deep_fetch.rb
73
70
  - lib/hashie/extensions/deep_merge.rb
74
71
  - lib/hashie/extensions/ignore_undeclared.rb
@@ -76,8 +73,10 @@ files:
76
73
  - lib/hashie/extensions/key_conversion.rb
77
74
  - lib/hashie/extensions/merge_initializer.rb
78
75
  - lib/hashie/extensions/method_access.rb
76
+ - lib/hashie/extensions/pretty_inspect.rb
77
+ - lib/hashie/extensions/stringify_keys.rb
78
+ - lib/hashie/extensions/symbolize_keys.rb
79
79
  - lib/hashie/hash.rb
80
- - lib/hashie/hash_extensions.rb
81
80
  - lib/hashie/mash.rb
82
81
  - lib/hashie/rash.rb
83
82
  - lib/hashie/trash.rb
@@ -85,6 +84,7 @@ files:
85
84
  - spec/hashie/clash_spec.rb
86
85
  - spec/hashie/dash_spec.rb
87
86
  - spec/hashie/extensions/coercion_spec.rb
87
+ - spec/hashie/extensions/dash/indifferent_access_spec.rb
88
88
  - spec/hashie/extensions/deep_fetch_spec.rb
89
89
  - spec/hashie/extensions/deep_merge_spec.rb
90
90
  - spec/hashie/extensions/ignore_undeclared_spec.rb
@@ -97,43 +97,36 @@ files:
97
97
  - spec/hashie/rash_spec.rb
98
98
  - spec/hashie/trash_spec.rb
99
99
  - spec/hashie/version_spec.rb
100
- - spec/spec.opts
101
100
  - spec/spec_helper.rb
102
101
  homepage: https://github.com/intridea/hashie
103
102
  licenses:
104
103
  - MIT
104
+ metadata: {}
105
105
  post_install_message:
106
106
  rdoc_options: []
107
107
  require_paths:
108
108
  - lib
109
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
110
  requirements:
112
- - - ! '>='
111
+ - - '>='
113
112
  - !ruby/object:Gem::Version
114
113
  version: '0'
115
- segments:
116
- - 0
117
- hash: 775336832915500848
118
114
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
115
  requirements:
121
- - - ! '>='
116
+ - - '>='
122
117
  - !ruby/object:Gem::Version
123
118
  version: '0'
124
- segments:
125
- - 0
126
- hash: 775336832915500848
127
119
  requirements: []
128
120
  rubyforge_project:
129
- rubygems_version: 1.8.25
121
+ rubygems_version: 2.0.14
130
122
  signing_key:
131
- specification_version: 3
123
+ specification_version: 4
132
124
  summary: Your friendly neighborhood hash library.
133
125
  test_files:
134
126
  - spec/hashie/clash_spec.rb
135
127
  - spec/hashie/dash_spec.rb
136
128
  - spec/hashie/extensions/coercion_spec.rb
129
+ - spec/hashie/extensions/dash/indifferent_access_spec.rb
137
130
  - spec/hashie/extensions/deep_fetch_spec.rb
138
131
  - spec/hashie/extensions/deep_merge_spec.rb
139
132
  - spec/hashie/extensions/ignore_undeclared_spec.rb
@@ -146,5 +139,4 @@ test_files:
146
139
  - spec/hashie/rash_spec.rb
147
140
  - spec/hashie/trash_spec.rb
148
141
  - spec/hashie/version_spec.rb
149
- - spec/spec.opts
150
142
  - spec/spec_helper.rb
@@ -1,47 +0,0 @@
1
- module Hashie
2
- module HashExtensions
3
- def self.included(base)
4
- # Don't tread on existing extensions of Hash by
5
- # adding methods that are likely to exist.
6
- %w(stringify_keys stringify_keys!).each do |hashie_method|
7
- base.send :alias_method, hashie_method, "hashie_#{hashie_method}" unless base.instance_methods.include?(hashie_method)
8
- end
9
- end
10
-
11
- # Destructively convert all of the keys of a Hash
12
- # to their string representations.
13
- def hashie_stringify_keys!
14
- keys.each do |k|
15
- self[k.to_s] = delete(k) unless String === k
16
- end
17
- self
18
- end
19
-
20
- # Convert all of the keys of a Hash
21
- # to their string representations.
22
- def hashie_stringify_keys
23
- dup.stringify_keys!
24
- end
25
-
26
- # Convert this hash into a Mash
27
- def to_mash
28
- ::Hashie::Mash.new(self)
29
- end
30
- end
31
-
32
- module PrettyInspect
33
- def self.included(base)
34
- base.send :alias_method, :hash_inspect, :inspect
35
- base.send :alias_method, :inspect, :hashie_inspect
36
- end
37
-
38
- def hashie_inspect
39
- ret = "#<#{self.class}"
40
- stringify_keys.keys.sort.each do |key|
41
- ret << " #{key}=#{self[key].inspect}"
42
- end
43
- ret << '>'
44
- ret
45
- end
46
- end
47
- end