rash 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source "http://rubygems.org"
2
2
  gemspec
@@ -27,16 +27,16 @@ You will now be able to access those keys through underscored key names (camelCa
27
27
  }
28
28
  })
29
29
 
30
- @rash.var_one # => 1
31
- @rash.two # => 2
32
- @rash.three # => 3
33
- @rash.var_four # => 4
34
- @rash.five_hump_humps # => 5
35
- @rash.nested.nested_one # => "One"
36
- @rash.nested.two # => "two"
37
- @rash.nested.nested_three # => "three"
38
- @rash.nested_two.nested_two # => 22
39
- @rash.nested_two # => 23
30
+ @rash.var_one # => 1
31
+ @rash.two # => 2
32
+ @rash.three # => 3
33
+ @rash.var_four # => 4
34
+ @rash.five_hump_humps # => 5
35
+ @rash.nested.nested_one # => "One"
36
+ @rash.nested.two # => "two"
37
+ @rash.nested.nested_three # => "three"
38
+ @rash.nested_two.nested_two # => 22
39
+ @rash.nested_two.nested_three # => 23
40
40
 
41
41
  == Note on Patches/Pull Requests
42
42
 
@@ -5,23 +5,39 @@ module Hashie
5
5
 
6
6
  protected
7
7
 
8
- def convert_key(key) #:nodoc:
9
- underscore_string(key.to_s)
10
- end
8
+ def convert_key(key) #:nodoc:
9
+ underscore_string(key.to_s)
10
+ end
11
11
 
12
- # converts a camel_cased string to a underscore string
13
- # subs spaces with underscores, strips whitespace
14
- # Same way ActiveSupport does string.underscore
15
- def underscore_string(str)
16
- str.to_s.strip.
17
- gsub(' ', '_').
18
- gsub(/::/, '/').
19
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
20
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
21
- tr("-", "_").
22
- squeeze("_").
23
- downcase
12
+ # Unlike its parent Mash, a Rash will convert other Hashie::Hash values to a Rash when assigning
13
+ # instead of respecting the existing subclass
14
+ def convert_value(val, duping=false) #:nodoc:
15
+ case val
16
+ when self.class
17
+ val.dup
18
+ when ::Hash
19
+ val = val.dup if duping
20
+ self.class.new(val)
21
+ when Array
22
+ val.collect{ |e| convert_value(e) }
23
+ else
24
+ val
24
25
  end
26
+ end
27
+
28
+ # converts a camel_cased string to a underscore string
29
+ # subs spaces with underscores, strips whitespace
30
+ # Same way ActiveSupport does string.underscore
31
+ def underscore_string(str)
32
+ str.to_s.strip.
33
+ gsub(' ', '_').
34
+ gsub(/::/, '/').
35
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
36
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
37
+ tr("-", "_").
38
+ squeeze("_").
39
+ downcase
40
+ end
25
41
 
26
42
  end
27
43
  end
@@ -1,3 +1,3 @@
1
1
  module Rash
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.version = Rash::VERSION
15
15
 
16
- s.add_dependency 'hashie', '~> 1.2.0'
16
+ s.add_dependency 'hashie', '~> 2.0.0'
17
17
  s.add_development_dependency 'rake', '~> 0.9'
18
18
  s.add_development_dependency 'rdoc', '~> 3.9'
19
19
  s.add_development_dependency 'rspec', '~> 2.5'
@@ -23,4 +23,3 @@ Gem::Specification.new do |s|
23
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
25
  end
26
-
@@ -57,6 +57,20 @@ describe Hashie::Rash do
57
57
  end
58
58
 
59
59
  it "should merge well with a Mash" do
60
+ merged = subject.merge Hashie::Mash.new(
61
+ :nested => {:fourTimes => "a charm"},
62
+ :nested3 => {:helloWorld => "hi"}
63
+ )
64
+
65
+ merged.nested.four_times.should == "a charm"
66
+ merged.nested.fourTimes.should == "a charm"
67
+ merged.nested3.should be_a(Hashie::Rash)
68
+ merged.nested3.hello_world.should == "hi"
69
+ merged.nested3.helloWorld.should == "hi"
70
+ merged[:nested3][:helloWorld].should == "hi"
71
+ end
72
+
73
+ it "should update well with a Mash" do
60
74
  subject.update Hashie::Mash.new(
61
75
  :nested => {:fourTimes => "a charm"},
62
76
  :nested3 => {:helloWorld => "hi"}
@@ -64,8 +78,33 @@ describe Hashie::Rash do
64
78
 
65
79
  subject.nested.four_times.should == "a charm"
66
80
  subject.nested.fourTimes.should == "a charm"
81
+ subject.nested3.should be_a(Hashie::Rash)
82
+ subject.nested3.hello_world.should == "hi"
83
+ subject.nested3.helloWorld.should == "hi"
84
+ subject[:nested3][:helloWorld].should == "hi"
85
+ end
86
+
87
+ it "should merge well with a Hash" do
88
+ merged = subject.merge({
89
+ :nested => {:fourTimes => "work like a charm"},
90
+ :nested3 => {:helloWorld => "hi"}
91
+ })
92
+
93
+ merged.nested.four_times.should == "work like a charm"
94
+ merged.nested.fourTimes.should == "work like a charm"
95
+ merged.nested3.should be_a(Hashie::Rash)
96
+ merged.nested3.hello_world.should == "hi"
97
+ merged.nested3.helloWorld.should == "hi"
98
+ merged[:nested3][:helloWorld].should == "hi"
99
+ end
100
+
101
+ it "should handle assigning a new Hash and convert it to a rash" do
102
+ subject.nested3 = {:helloWorld => "hi"}
103
+
104
+ subject.nested3.should be_a(Hashie::Rash)
67
105
  subject.nested3.hello_world.should == "hi"
68
106
  subject.nested3.helloWorld.should == "hi"
107
+ subject[:nested3][:helloWorld].should == "hi"
69
108
  end
70
109
 
71
110
  it "should allow initializing reader" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - tcocca
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-29 00:00:00 -05:00
18
+ date: 2013-02-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,16 +24,16 @@ dependencies:
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- hash: 31
27
+ hash: 15
28
28
  segments:
29
- - 1
30
29
  - 2
31
30
  - 0
32
- version: 1.2.0
33
- version_requirements: *id001
31
+ - 0
32
+ version: 2.0.0
34
33
  name: hashie
35
34
  type: :runtime
36
35
  prerelease: false
36
+ version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -45,10 +45,10 @@ dependencies:
45
45
  - 0
46
46
  - 9
47
47
  version: "0.9"
48
- version_requirements: *id002
49
48
  name: rake
50
49
  type: :development
51
50
  prerelease: false
51
+ version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
@@ -60,10 +60,10 @@ dependencies:
60
60
  - 3
61
61
  - 9
62
62
  version: "3.9"
63
- version_requirements: *id003
64
63
  name: rdoc
65
64
  type: :development
66
65
  prerelease: false
66
+ version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
68
68
  requirement: &id004 !ruby/object:Gem::Requirement
69
69
  none: false
@@ -75,10 +75,10 @@ dependencies:
75
75
  - 2
76
76
  - 5
77
77
  version: "2.5"
78
- version_requirements: *id004
79
78
  name: rspec
80
79
  type: :development
81
80
  prerelease: false
81
+ version_requirements: *id004
82
82
  description: simple extension to Hashie::Mash for rubyified keys, all keys are converted to underscore to eliminate horrible camelCasing
83
83
  email: tom.cocca@gmail.com
84
84
  executables: []