tworgy-ruby 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,4 +29,12 @@ class Hash
29
29
  def recursively!(&block)
30
30
  replace(recursively(&block))
31
31
  end
32
+
33
+ def ostructify
34
+ result = inject({}) do |hash, (key, value)|
35
+ hash[key] = value.is_a?(Hash) ? value.ostructify : value
36
+ hash
37
+ end
38
+ OpenStruct.new result
39
+ end
32
40
  end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
+
3
+ describe "recursively" do
4
+
5
+ describe Hash do
6
+
7
+ it 'should symbolize the keys recursively' do
8
+ {'a' => {'b' => 3}}.recursively { |hash| symbolize_keys(hash) }.should == {:a => {:b => 3}}
9
+ end
10
+
11
+ describe 'ostructify' do
12
+ before :each do
13
+ @object = {:person => {:name => 'bob', :age => 5}}.ostructify
14
+ end
15
+
16
+ it 'should turn a nested hash into nested OpenStructs' do
17
+ @object.person.name.should == 'bob'
18
+ @object.person.age.should == 5
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def symbolize_keys(hash)
25
+ hash.inject({}) do |result, (key, value)|
26
+ result[key.to_sym] = value
27
+ result
28
+ end
29
+ end
30
+
31
+
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
3
5
  require 'tworgy-ruby'
4
6
  require 'spec'
5
7
  require 'spec/autorun'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworgy-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Holroyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 +11:00
12
+ date: 2009-11-23 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ files:
40
40
  - lib/tworgy/recursively.rb
41
41
  - lib/tworgy/standard_extensions.rb
42
42
  - lib/tworgy/tmail.rb
43
+ - spec/lib/tworgy/recursively_spec.rb
43
44
  - spec/spec.opts
44
45
  - spec/spec_helper.rb
45
- - spec/tworgy-ruby-ext_spec.rb
46
46
  has_rdoc: true
47
47
  homepage: http://github.com/matholroyd/tworgy-ruby
48
48
  licenses: []
@@ -72,5 +72,5 @@ signing_key:
72
72
  specification_version: 3
73
73
  summary: Handy Ruby extensions
74
74
  test_files:
75
+ - spec/lib/tworgy/recursively_spec.rb
75
76
  - spec/spec_helper.rb
76
- - spec/tworgy-ruby-ext_spec.rb
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "TworgyRubyExt" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
- end