hashie 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --colour
2
- --format=nested
2
+ --format=documentation
@@ -1,3 +1,7 @@
1
+ ## 2.1.2 (5/12/2014)
2
+
3
+ * [#169](https://github.com/intridea/hashie/pull/169): Hash#to_hash will also convert nested objects that implement `to_hash` - [@gregory](https://github.com/gregory).
4
+
1
5
  ## 2.1.1 (4/12/2014)
2
6
 
3
7
  * [#144](https://github.com/intridea/hashie/issues/144): Fixed regression invoking `to_hash` with no parameters - [@mbleigh](https://github.com/mbleigh).
@@ -7,7 +11,7 @@
7
11
  * [#134](https://github.com/intridea/hashie/pull/134): Add deep_fetch extension for nested access - [@tylerdooling](https://github.com/tylerdooling).
8
12
  * Removed support for Ruby 1.8.7 - [@dblock](https://github.com/dblock).
9
13
  * Ruby style now enforced with Rubocop - [@dblock](https://github.com/dblock).
10
- * [#138](https://github.com/intridea/hashie/pull/138): Added Hashie#Rash, a hash whose keys can be regular expressions or ranges - [@epitron](https://github.com/epitron).
14
+ * [#138](https://github.com/intridea/hashie/pull/138): Added Hashie::Rash, a hash whose keys can be regular expressions or ranges - [@epitron](https://github.com/epitron).
11
15
  * [#131](https://github.com/intridea/hashie/pull/131): Added IgnoreUndeclared, an extension to silently ignore undeclared properties at intialization - [@righi](https://github.com/righi).
12
16
  * [#136](https://github.com/intridea/hashie/issues/136): Removed Hashie::Extensions::Structure - [@markiz](https://github.com/markiz).
13
17
  * [#107](https://github.com/intridea/hashie/pull/107): Fixed excessive value conversions, poor performance of deep merge in Hashie::Mash - [@davemitchell](https://github.com/dblock), [@dblock](https://github.com/dblock).
@@ -19,7 +19,7 @@ module Hashie
19
19
  out[assignment_key] << (Hash === array_object ? flexibly_convert_to_hash(array_object, options) : array_object)
20
20
  end
21
21
  else
22
- out[assignment_key] = Hash === self[k] ? flexibly_convert_to_hash(self[k], options) : self[k]
22
+ out[assignment_key] = (Hash === self[k] || self[k].respond_to?(:to_hash)) ? flexibly_convert_to_hash(self[k], options) : self[k]
23
23
  end
24
24
  end
25
25
  out
@@ -1,3 +1,3 @@
1
1
  module Hashie
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
3
  end
@@ -220,17 +220,17 @@ describe DashTest do
220
220
  end
221
221
 
222
222
  it 'checks if a property exists' do
223
- expect(described_class.property?('first_name')).to be_true
224
- expect(described_class.property?(:first_name)).to be_true
223
+ expect(described_class.property?('first_name')).to be true
224
+ expect(described_class.property?(:first_name)).to be true
225
225
  end
226
226
 
227
227
  it 'checks if a property is required' do
228
- expect(described_class.required?('first_name')).to be_true
229
- expect(described_class.required?(:first_name)).to be_true
228
+ expect(described_class.required?('first_name')).to be true
229
+ expect(described_class.required?(:first_name)).to be true
230
230
  end
231
231
 
232
232
  it 'doesnt include property from subclass' do
233
- expect(described_class.property?(:last_name)).to be_false
233
+ expect(described_class.property?(:last_name)).to be false
234
234
  end
235
235
 
236
236
  it 'lists declared defaults' do
@@ -238,7 +238,7 @@ describe DashTest do
238
238
  end
239
239
 
240
240
  it 'allows properties that end in bang' do
241
- expect(PropertyBangTest.property?(:important!)).to be_true
241
+ expect(PropertyBangTest.property?(:important!)).to be true
242
242
  end
243
243
  end
244
244
 
@@ -329,10 +329,10 @@ describe Subclassed do
329
329
  it { should respond_to(:last_name=) }
330
330
 
331
331
  it 'has one additional property' do
332
- expect(described_class.property?(:last_name)).to be_true
332
+ expect(described_class.property?(:last_name)).to be true
333
333
  end
334
334
 
335
335
  it "didn't override superclass inheritance logic" do
336
- expect(described_class.instance_variable_get('@inheritance_test')).to be_true
336
+ expect(described_class.instance_variable_get('@inheritance_test')).to be true
337
337
  end
338
338
  end
@@ -103,12 +103,12 @@ describe Hashie::Extensions::IndifferentAccess do
103
103
  it 'removes old keys' do
104
104
  [:foo, 'foo'].each do |k|
105
105
  expect(h[k]).to be_nil
106
- expect(h.key?(k)).to be_false
106
+ expect(h.key?(k)).to be false
107
107
  end
108
108
  end
109
109
 
110
110
  it 'creates new keys with indifferent access' do
111
- [:bar, 'bar', :hi, 'hi'].each { |k| expect(h.key?(k)).to be_true }
111
+ [:bar, 'bar', :hi, 'hi'].each { |k| expect(h.key?(k)).to be true }
112
112
  expect(h[:bar]).to eq 'baz'
113
113
  expect(h['bar']).to eq 'baz'
114
114
  expect(h[:hi]).to eq 'bye'
@@ -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 true
7
7
  expect(mash.some).to eq 'hash'
8
8
  end
9
9
 
@@ -43,4 +43,24 @@ describe Hash do
43
43
  h[:key] = BareCustomMash.new
44
44
  expect { h.to_hash }.not_to raise_error
45
45
  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
46
66
  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 true
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 false
37
37
  subject.test = 'abc'
38
- expect(subject.test?).to be_true
38
+ expect(subject.test?).to be true
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 true
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 true
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 true
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 true
94
94
  end
95
95
 
96
96
  it 'allows for multi-level assignment through bang methods' do
@@ -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 true
222
+ expect(subject.details?).to be true
223
223
  expect(subject.middle_name).to eq 'Cain'
224
- expect(subject.details.city?).to be_true
224
+ expect(subject.details.city?).to be true
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 false
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 false
233
233
  expect(subject).not_to respond_to(:last_name)
234
234
  end
235
235
  end
@@ -352,7 +352,7 @@ describe Hashie::Mash do
352
352
 
353
353
  it 'converts hashes recursively into Hashie::Mashes' do
354
354
  converted = Hashie::Mash.new(a: { b: 1, c: { d: 23 } })
355
- expect(converted.a.is_a?(Hashie::Mash)).to be_true
355
+ expect(converted.a.is_a?(Hashie::Mash)).to be true
356
356
  expect(converted.a.b).to eq 1
357
357
  expect(converted.a.c.d).to eq 23
358
358
  end
@@ -379,15 +379,15 @@ describe Hashie::Mash do
379
379
  expect(initial.default_proc).not_to be_nil
380
380
  expect(initial.default).to be_nil
381
381
  expect(initial.test).to eq []
382
- expect(initial.test?).to be_true
382
+ expect(initial.test?).to be true
383
383
  end
384
384
 
385
385
  it 'converts Hashie::Mashes within Arrays back to Hashes' do
386
386
  initial_hash = { 'a' => [{ 'b' => 12, 'c' => ['d' => 50, 'e' => 51] }, 23] }
387
387
  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
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
391
391
  end
392
392
  end
393
393
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Michael Bleigh
@@ -9,34 +10,38 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-04-12 00:00:00.000000000 Z
13
+ date: 2014-06-12 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rake
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
- - - '>='
20
+ - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: '0'
21
23
  type: :development
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
- - - '>='
28
+ - - ! '>='
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0'
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: rspec
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
- - - '>='
36
+ - - ! '>='
33
37
  - !ruby/object:Gem::Version
34
38
  version: '0'
35
39
  type: :development
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
- - - '>='
44
+ - - ! '>='
40
45
  - !ruby/object:Gem::Version
41
46
  version: '0'
42
47
  description: Hashie is a collection of classes and mixins that make hashes more powerful.
@@ -97,26 +102,33 @@ files:
97
102
  homepage: https://github.com/intridea/hashie
98
103
  licenses:
99
104
  - MIT
100
- metadata: {}
101
105
  post_install_message:
102
106
  rdoc_options: []
103
107
  require_paths:
104
108
  - lib
105
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
106
111
  requirements:
107
- - - '>='
112
+ - - ! '>='
108
113
  - !ruby/object:Gem::Version
109
114
  version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 775336832915500848
110
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
111
120
  requirements:
112
- - - '>='
121
+ - - ! '>='
113
122
  - !ruby/object:Gem::Version
114
123
  version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 775336832915500848
115
127
  requirements: []
116
128
  rubyforge_project:
117
- rubygems_version: 2.0.14
129
+ rubygems_version: 1.8.25
118
130
  signing_key:
119
- specification_version: 4
131
+ specification_version: 3
120
132
  summary: Your friendly neighborhood hash library.
121
133
  test_files:
122
134
  - spec/hashie/clash_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 669a459e63fb50152c48b98abf0bce58e5e138e5
4
- data.tar.gz: 49b29974978742dab0b2c228dd2c473df1d89732
5
- SHA512:
6
- metadata.gz: 513d09bc3690cfa9a3913354c80bb9bb34321013ba46a710c8a4649ff3967218f4ed04a45bb79451623fadc2d340bb174b260ab8f9b424733c2d16f334f1d9d6
7
- data.tar.gz: aea99e5db0b7c58499b45b6ca806fe99bb94a4e8e5c74df22af74a56844104778ba8a328d8e024a7f090daceaf092ed0eb25ae1d302dc901f4b05268ec851756