hashie 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,3 +4,4 @@ rvm:
4
4
  - rbx
5
5
  - ree
6
6
  - ruby-head
7
+ - jruby
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hashie (1.1.0)
4
+ hashie (1.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -23,6 +23,7 @@ GEM
23
23
  thor (0.14.6)
24
24
 
25
25
  PLATFORMS
26
+ java
26
27
  ruby
27
28
 
28
29
  DEPENDENCIES
@@ -7,11 +7,12 @@ module Hashie
7
7
  class Hash < Hash
8
8
  include Hashie::HashExtensions
9
9
 
10
- # Converts a mash back to a hash (with stringified keys)
11
- def to_hash
10
+ # Converts a mash back to a hash.
11
+ def to_hash(options = {})
12
12
  out = {}
13
13
  keys.each do |k|
14
- out[k] = Hashie::Hash === self[k] ? self[k].to_hash : self[k]
14
+ key = options[:symbolize_keys] ? k.to_sym : k.to_s
15
+ out[key] = Hashie::Hash === self[k] ? self[k].to_hash : self[k]
15
16
  end
16
17
  out
17
18
  end
@@ -38,7 +38,7 @@ module Hashie
38
38
  end
39
39
 
40
40
  def hashie_inspect
41
- ret = "<##{self.class.to_s}"
41
+ ret = "#<#{self.class.to_s}"
42
42
  stringify_keys.keys.sort.each do |key|
43
43
  ret << " #{key}=#{self[key].inspect}"
44
44
  end
@@ -55,7 +55,13 @@ module Hashie
55
55
  default ? super(default) : super(&blk)
56
56
  end
57
57
 
58
- class << self; alias [] new; end
58
+ class << self
59
+ alias [] new
60
+
61
+ def subkey_class
62
+ self
63
+ end
64
+ end
59
65
 
60
66
  def id #:nodoc:
61
67
  key?("id") ? self["id"] : super
@@ -104,6 +110,9 @@ module Hashie
104
110
  def key?(key)
105
111
  super(convert_key(key))
106
112
  end
113
+ alias_method :has_key?, :key?
114
+ alias_method :include?, :key?
115
+ alias_method :member?, :key?
107
116
 
108
117
  # Performs a deep_update on a duplicate of the
109
118
  # current mash.
@@ -177,7 +186,7 @@ module Hashie
177
186
  val.dup
178
187
  when ::Hash
179
188
  val = val.dup if duping
180
- self.class.new(val)
189
+ self.class.subkey_class.new.merge(val)
181
190
  when Array
182
191
  val.collect{ |e| convert_value(e) }
183
192
  else
@@ -1,3 +1,3 @@
1
1
  module Hashie
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -28,12 +28,12 @@ describe DashTest do
28
28
 
29
29
  it('subclasses Hashie::Hash') { should respond_to(:to_mash) }
30
30
 
31
- its(:to_s) { should == '<#DashTest count=0 email="bob@example.com" first_name="Bob">' }
31
+ its(:to_s) { should == '#<DashTest count=0 email="bob@example.com" first_name="Bob">' }
32
32
 
33
33
  it 'lists all set properties in inspect' do
34
34
  subject.first_name = 'Bob'
35
35
  subject.email = 'bob@example.com'
36
- subject.inspect.should == '<#DashTest count=0 email="bob@example.com" first_name="Bob">'
36
+ subject.inspect.should == '#<DashTest count=0 email="bob@example.com" first_name="Bob">'
37
37
  end
38
38
 
39
39
  its(:count) { should be_zero }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hash do
3
+ describe Hashie::Hash do
4
4
  it "should be convertible to a Hashie::Mash" do
5
5
  mash = Hashie::Hash[:some => "hash"].to_mash
6
6
  mash.is_a?(Hashie::Mash).should be_true
@@ -19,4 +19,14 @@ describe Hash do
19
19
  hash.should == Hashie::Hash[:a => "hey", 123 => "bob"]
20
20
  stringified_hash.should == Hashie::Hash["a" => "hey", "123" => "bob"]
21
21
  end
22
- end
22
+
23
+ describe '#to_hash' do
24
+ it 'should convert it to a hash with string keys by default' do
25
+ Hashie::Hash.new.merge(:a => 'hey', :b => 'foo').to_hash.should == {'a' => 'hey', 'b' => 'foo'}
26
+ end
27
+
28
+ it 'should convert to a hash with symbol keys if :symbolize_keys is passed in' do
29
+ Hashie::Hash.new.merge('a' => 'hey', 'b' => 'doo').to_hash(:symbolize_keys => true).should == {:a => 'hey', :b => 'doo'}
30
+ end
31
+ end
32
+ end
@@ -225,16 +225,6 @@ describe Hashie::Mash do
225
225
  it 'should respond to a set key' do
226
226
  Hashie::Mash.new(:abc => 'def').should be_respond_to(:abc)
227
227
  end
228
-
229
- it "should delegate properly using delegate library" do
230
- class MashDelegate < DelegateClass(Hashie::Mash)
231
- end
232
-
233
- delegate = MashDelegate.new(Hashie::Mash.new(:foo => 100))
234
- delegate.foo.should == 100
235
- delegate.should respond_to(:foo)
236
- expect { delegate.bar }.to raise_error(NoMethodError)
237
- end
238
228
  end
239
229
 
240
230
  context "#initialize" do
@@ -276,13 +266,15 @@ describe Hashie::Mash do
276
266
  initial.test?.should be_true
277
267
  end
278
268
 
279
- describe "to_json" do
269
+ describe '.subkey_class' do
270
+ it 'should be able to define a subkey class different from itself' do
271
+ class CustomSubkeyHash < Hashie::Mash
272
+ def self.subkey_class; Hashie::Mash end
273
+ end
280
274
 
281
- it "should render to_json" do
282
- @mash.foo = :bar
283
- @mash.bar = {"homer" => "simpson"}
284
- expected = {"foo" => "bar", "bar" => {"homer" => "simpson"}}
285
- JSON.parse(@mash.to_json).should == expected
275
+ subhash = CustomSubkeyHash.new(:subhash => {:abc => :def})[:subhash]
276
+ subhash.should_not be_kind_of(CustomSubkeyHash)
277
+ subhash.should be_kind_of(Hashie::Mash)
286
278
  end
287
279
  end
288
280
  end
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- require 'json'
3
2
 
4
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
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: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-29 00:00:00.000000000 Z
12
+ date: 2011-10-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70102343819800 !ruby/object:Gem::Requirement
16
+ requirement: &70100391048320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70102343819800
24
+ version_requirements: *70100391048320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70102343818980 !ruby/object:Gem::Requirement
27
+ requirement: &70100391047700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.5'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70102343818980
35
+ version_requirements: *70100391047700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard
38
- requirement: &70102343818420 !ruby/object:Gem::Requirement
38
+ requirement: &70100391047200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70102343818420
46
+ version_requirements: *70100391047200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &70102343817640 !ruby/object:Gem::Requirement
49
+ requirement: &70100391046540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70102343817640
57
+ version_requirements: *70100391046540
58
58
  description: Hashie is a small collection of tools that make hashes more powerful.
59
59
  Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).
60
60
  email:
@@ -73,7 +73,6 @@ files:
73
73
  - LICENSE
74
74
  - README.rdoc
75
75
  - Rakefile
76
- - VERSION
77
76
  - hashie.gemspec
78
77
  - lib/hashie.rb
79
78
  - lib/hashie/clash.rb
@@ -104,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
103
  version: '0'
105
104
  segments:
106
105
  - 0
107
- hash: -1452450375686029254
106
+ hash: 839965074967514567
108
107
  required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  none: false
110
109
  requirements:
@@ -113,10 +112,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
112
  version: '0'
114
113
  segments:
115
114
  - 0
116
- hash: -1452450375686029254
115
+ hash: 839965074967514567
117
116
  requirements: []
118
117
  rubyforge_project:
119
- rubygems_version: 1.8.5.1
118
+ rubygems_version: 1.8.10
120
119
  signing_key:
121
120
  specification_version: 3
122
121
  summary: Your friendly neighborhood hash toolkit.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0