deepopenstruct 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- MIT-LICENSE
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ MIT-LICENSE
data/.gitignore CHANGED
@@ -1,23 +1,23 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- *.gem
21
- *.log
22
-
23
- ## PROJECT::SPECIFIC
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gem
21
+ *.log
22
+
23
+ ## PROJECT::SPECIFIC
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 Aaron Gough (http://thingsaaronmade.com/)
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 Aaron Gough (http://thingsaaronmade.com/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,50 +1,50 @@
1
- == deepopenstruct
2
-
3
- DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.
4
-
5
- === Installation
6
-
7
- gem install deepopenstruct
8
-
9
- === Usage
10
-
11
- require 'rubygems'
12
- require 'deepopenstruct'
13
-
14
- complex_data = {
15
- :name => "Bob Winkle",
16
- :age => 65,
17
- :jobs => [
18
- {'start_year' => 1980, 'title' => 'Chef'},
19
- {'start_year' => 1985, 'title' => 'Programmer'}
20
- ],
21
- :attributes => {
22
- :birthplace => "Darwin",
23
- :year_of_birth => 1945
24
- }
25
- }
26
-
27
- simple_data = DeepOpenStruct.load(complex_data)
28
-
29
- simple_data.name
30
- # => "Bob Winkle"
31
-
32
- simple_data.jobs.first.title
33
- # => "Chef"
34
-
35
- simple_data.attributes.birthplace
36
- # => "Darwin"
37
-
38
- === Note on Patches/Pull Requests
39
-
40
- * Fork the project.
41
- * Make your feature addition or bug fix.
42
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
43
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
44
- * Send me a pull request! Bonus points for topic/feature branches.
45
-
46
- === Author & Credits
47
-
48
- Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
49
-
1
+ == deepopenstruct
2
+
3
+ DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.
4
+
5
+ === Installation
6
+
7
+ gem install deepopenstruct
8
+
9
+ === Usage
10
+
11
+ require 'rubygems'
12
+ require 'deepopenstruct'
13
+
14
+ complex_data = {
15
+ :name => "Bob Winkle",
16
+ :age => 65,
17
+ :jobs => [
18
+ {'start_year' => 1980, 'title' => 'Chef'},
19
+ {'start_year' => 1985, 'title' => 'Programmer'}
20
+ ],
21
+ :attributes => {
22
+ :birthplace => "Darwin",
23
+ :year_of_birth => 1945
24
+ }
25
+ }
26
+
27
+ simple_data = DeepOpenStruct.load(complex_data)
28
+
29
+ simple_data.name
30
+ # => "Bob Winkle"
31
+
32
+ simple_data.jobs.first.title
33
+ # => "Chef"
34
+
35
+ simple_data.attributes.birthplace
36
+ # => "Darwin"
37
+
38
+ === Note on Patches/Pull Requests
39
+
40
+ * Fork the project.
41
+ * Make your feature addition or bug fix.
42
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
43
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
44
+ * Send me a pull request! Bonus points for topic/feature branches.
45
+
46
+ === Author & Credits
47
+
48
+ Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
49
+
50
50
  Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
data/Rakefile CHANGED
@@ -1,52 +1,52 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "deepopenstruct"
8
- gem.summary = %Q{A simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays}
9
- gem.description = %Q{DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.}
10
- gem.email = "aaron@aarongough.com"
11
- gem.homepage = "http://github.com/aarongough/deepopenstruct"
12
- gem.authors = ["Aaron Gough"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
19
-
20
- require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/*_test.rb'
24
- test.verbose = true
25
- end
26
-
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
- task :test => :check_dependencies
41
-
42
- task :default => :test
43
-
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "deepopenstruct #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "deepopenstruct"
8
+ gem.summary = %Q{A simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays}
9
+ gem.description = %Q{DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.}
10
+ gem.email = "aaron@aarongough.com"
11
+ gem.homepage = "http://github.com/aarongough/deepopenstruct"
12
+ gem.authors = ["Aaron Gough"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "deepopenstruct #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{deepopenstruct}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Gough"]
12
- s.date = %q{2010-06-04}
12
+ s.date = %q{2010-08-23}
13
13
  s.description = %q{DeepOpenStruct is a simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays. It is particularly suitable for creating easy-to-use data structures from YAML files, and as such is a useful tool for creating simple reflective API wrappers.}
14
14
  s.email = %q{aaron@aarongough.com}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.homepage = %q{http://github.com/aarongough/deepopenstruct}
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
34
+ s.rubygems_version = %q{1.3.6}
35
35
  s.summary = %q{A simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays}
36
36
  s.test_files = [
37
37
  "test/setup/test_unit_extensions.rb",
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
44
  s.specification_version = 3
45
45
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
47
  else
48
48
  end
49
49
  else
@@ -1,26 +1,35 @@
1
- require 'ostruct'
2
-
3
- class DeepOpenStruct
4
- def self.load(item)
5
- raise ArgumentError, "DeepOpenStruct must be passed a Hash or Array" unless(item.is_a?(Hash) || item.is_a?(Array))
6
- item = item.clone
7
- if(item.is_a?(Hash))
8
- item.merge!(item) do |key, value, oldvalue|
9
- if(value.is_a?(Hash) || value.is_a?(Array))
10
- DeepOpenStruct.load(value)
11
- else
12
- value
13
- end
14
- end
15
- return OpenStruct.new(item)
16
- elsif(item.is_a?(Array))
17
- return item.map do |value|
18
- if(value.is_a?(Hash) || value.is_a?(Array))
19
- DeepOpenStruct.load(value)
20
- else
21
- value
22
- end
23
- end
24
- end
25
- end
1
+ require 'ostruct'
2
+
3
+ class PatchedOpenStruct < OpenStruct
4
+ def id
5
+ @table[:id]
6
+ end
7
+
8
+ def type
9
+ @table[:type]
10
+ end
11
+ end
12
+
13
+ class DeepOpenStruct
14
+ def self.load(item)
15
+ raise ArgumentError, "DeepOpenStruct must be passed a Hash or Array" unless(item.is_a?(Hash) || item.is_a?(Array))
16
+ if(item.is_a?(Hash))
17
+ item = item.merge(item) do |key, value, oldvalue|
18
+ if(value.is_a?(Hash) || value.is_a?(Array))
19
+ DeepOpenStruct.load(value)
20
+ else
21
+ value
22
+ end
23
+ end
24
+ return PatchedOpenStruct.new(item)
25
+ elsif(item.is_a?(Array))
26
+ return item.map do |value|
27
+ if(value.is_a?(Hash) || value.is_a?(Array))
28
+ DeepOpenStruct.load(value)
29
+ else
30
+ value
31
+ end
32
+ end
33
+ end
34
+ end
26
35
  end
@@ -1,21 +1,21 @@
1
- module Test::Unit
2
- # Used to fix a minor minitest/unit incompatibility in flexmock
3
- AssertionFailedError = Class.new(StandardError)
4
-
5
- class TestCase
6
-
7
- def self.test(name, &block)
8
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
9
- defined = instance_method(test_name) rescue false
10
- raise "#{test_name} is already defined in #{self}" if defined
11
- if block_given?
12
- define_method(test_name, &block)
13
- else
14
- define_method(test_name) do
15
- flunk "No implementation provided for #{name}"
16
- end
17
- end
18
- end
19
-
20
- end
1
+ module Test::Unit
2
+ # Used to fix a minor minitest/unit incompatibility in flexmock
3
+ AssertionFailedError = Class.new(StandardError)
4
+
5
+ class TestCase
6
+
7
+ def self.test(name, &block)
8
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
9
+ defined = instance_method(test_name) rescue false
10
+ raise "#{test_name} is already defined in #{self}" if defined
11
+ if block_given?
12
+ define_method(test_name, &block)
13
+ else
14
+ define_method(test_name) do
15
+ flunk "No implementation provided for #{name}"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
21
  end
@@ -1,17 +1,17 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'ostruct'
4
-
5
- $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- require 'deepopenstruct'
8
-
9
- require_files = []
10
- require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
11
-
12
- require_files.each do |file|
13
- require File.expand_path(file)
14
- end
15
-
16
- class Test::Unit::TestCase
17
- end
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'ostruct'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'deepopenstruct'
8
+
9
+ require_files = []
10
+ require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
11
+
12
+ require_files.each do |file|
13
+ require File.expand_path(file)
14
+ end
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -1,73 +1,85 @@
1
- require 'test_helper'
2
-
3
- class TestDeepOpenStruct < Test::Unit::TestCase
4
-
5
- test "should convert hash into openstruct" do
6
- hash = {:item_1 => 1, 'item_2' => 2, "item_3" => 3}
7
- assert_nothing_raised do
8
- deepstruct = DeepOpenStruct.load(hash)
9
- assert_equal 1, deepstruct.item_1
10
- assert_equal 2, deepstruct.item_2
11
- assert_equal 3, deepstruct.item_3
12
- end
13
- end
14
-
15
- test "should convert array of hashes into array of openstructs" do
16
- array = [{:hash_1 => 1}, {:hash_2 => 2}, {:hash_3 => 3}]
17
- assert_nothing_raised do
18
- deepstruct = DeepOpenStruct.load(array)
19
- assert_equal 1, deepstruct[0].hash_1
20
- assert_equal 2, deepstruct[1].hash_2
21
- assert_equal 3, deepstruct[2].hash_3
22
- end
23
- end
24
-
25
- test "should convert nested hash into nested openstruct" do
26
- hash = {:hash_1 => {:foo => :blah}, :hash_2 => {:foo => :blah, :deep_nest => {:foo => :blah}}}
27
- assert_nothing_raised do
28
- deepstruct = DeepOpenStruct.load(hash)
29
- assert_equal :blah, deepstruct.hash_1.foo
30
- assert_equal :blah, deepstruct.hash_2.foo
31
- assert_equal :blah, deepstruct.hash_2.deep_nest.foo
32
- end
33
- end
34
-
35
- test "should convert arrays of hashes in hash into arrays of openstructs" do
36
- hash = {:array => [1, 2, {:foo => :blah, :array => [3, 4, {:see => :more}]}]}
37
- assert_nothing_raised do
38
- deepstruct = DeepOpenStruct.load(hash)
39
- assert_kind_of Array, deepstruct.array
40
- assert_equal 1, deepstruct.array[0]
41
- assert_equal 2, deepstruct.array[1]
42
- assert_kind_of OpenStruct, deepstruct.array[2]
43
- assert_equal :blah, deepstruct.array[2].foo
44
- assert_kind_of Array, deepstruct.array[2].array
45
- assert_equal 3, deepstruct.array[2].array[0]
46
- assert_equal 4, deepstruct.array[2].array[1]
47
- assert_kind_of OpenStruct, deepstruct.array[2].array[2]
48
- assert_equal :more, deepstruct.array[2].array[2].see
49
- end
50
- end
51
-
52
- test "should raise ArgumentError if argument supplied to initialize is not a Hash or Array" do
53
- [1, "hello", 3.00, OpenStruct.new({:blah => :foo})].each do |item|
54
- assert_raises ArgumentError, "should have raised error when initialized with #{item.class}" do
55
- test = DeepOpenStruct.load(item)
56
- end
57
- end
58
- end
59
-
60
- test "should not not create side effects on array" do
61
- array = [{:hash_1 => 1}, {:hash_2 => 2}, {:hash_3 => 3}]
62
- deepstruct = DeepOpenStruct.load(array)
63
- assert_kind_of Hash, array[0]
64
- end
65
-
66
- test "should not not create side effects on hash" do
67
- hash = {:array => [1, 2, {:foo => :blah, :array => [3, 4, {:see => :more}]}]}
68
- deepstruct = DeepOpenStruct.load(hash)
69
- assert_kind_of Hash, hash[:array][2]
70
- assert_kind_of Hash, hash[:array][2][:array][2]
71
- end
72
-
73
- end
1
+ require 'test_helper'
2
+
3
+ class TestDeepOpenStruct < Test::Unit::TestCase
4
+
5
+ test "should convert hash into openstruct" do
6
+ hash = {:item_1 => 1, 'item_2' => 2, "item_3" => 3}
7
+ assert_nothing_raised do
8
+ deepstruct = DeepOpenStruct.load(hash)
9
+ assert_equal 1, deepstruct.item_1
10
+ assert_equal 2, deepstruct.item_2
11
+ assert_equal 3, deepstruct.item_3
12
+ end
13
+ end
14
+
15
+ test "should convert array of hashes into array of openstructs" do
16
+ array = [{:hash_1 => 1}, {:hash_2 => 2}, {:hash_3 => 3}]
17
+ assert_nothing_raised do
18
+ deepstruct = DeepOpenStruct.load(array)
19
+ assert_equal 1, deepstruct[0].hash_1
20
+ assert_equal 2, deepstruct[1].hash_2
21
+ assert_equal 3, deepstruct[2].hash_3
22
+ end
23
+ end
24
+
25
+ test "should convert nested hash into nested openstruct" do
26
+ hash = {:hash_1 => {:foo => :blah}, :hash_2 => {:foo => :blah, :deep_nest => {:foo => :blah}}}
27
+ assert_nothing_raised do
28
+ deepstruct = DeepOpenStruct.load(hash)
29
+ assert_equal :blah, deepstruct.hash_1.foo
30
+ assert_equal :blah, deepstruct.hash_2.foo
31
+ assert_equal :blah, deepstruct.hash_2.deep_nest.foo
32
+ end
33
+ end
34
+
35
+ test "should convert arrays of hashes in hash into arrays of openstructs" do
36
+ hash = {:array => [1, 2, {:foo => :blah, :array => [3, 4, {:see => :more}]}]}
37
+ assert_nothing_raised do
38
+ deepstruct = DeepOpenStruct.load(hash)
39
+ assert_kind_of Array, deepstruct.array
40
+ assert_equal 1, deepstruct.array[0]
41
+ assert_equal 2, deepstruct.array[1]
42
+ assert_kind_of OpenStruct, deepstruct.array[2]
43
+ assert_equal :blah, deepstruct.array[2].foo
44
+ assert_kind_of Array, deepstruct.array[2].array
45
+ assert_equal 3, deepstruct.array[2].array[0]
46
+ assert_equal 4, deepstruct.array[2].array[1]
47
+ assert_kind_of OpenStruct, deepstruct.array[2].array[2]
48
+ assert_equal :more, deepstruct.array[2].array[2].see
49
+ end
50
+ end
51
+
52
+ test "should raise ArgumentError if argument supplied to initialize is not a Hash or Array" do
53
+ [1, "hello", 3.00, OpenStruct.new({:blah => :foo})].each do |item|
54
+ assert_raises ArgumentError, "should have raised error when initialized with #{item.class}" do
55
+ test = DeepOpenStruct.load(item)
56
+ end
57
+ end
58
+ end
59
+
60
+ test "should not not create side effects on array" do
61
+ array = [{:hash_1 => 1}, {:hash_2 => 2}, {:hash_3 => 3}]
62
+ deepstruct = DeepOpenStruct.load(array)
63
+ assert_kind_of Hash, array[0]
64
+ end
65
+
66
+ test "should not not create side effects on hash" do
67
+ hash = {:array => [1, 2, {:foo => :blah, :array => [3, 4, {:see => :more}]}]}
68
+ deepstruct = DeepOpenStruct.load(hash)
69
+ assert_kind_of Hash, hash[:array][2]
70
+ assert_kind_of Hash, hash[:array][2][:array][2]
71
+ end
72
+
73
+ test "should allow overriding of :id" do
74
+ hash = {:id => "blah"}
75
+ deepstruct = DeepOpenStruct.load(hash)
76
+ assert_equal "blah", deepstruct.id
77
+ end
78
+
79
+ test "should allow overriding of :type" do
80
+ hash = {:type => "blah"}
81
+ deepstruct = DeepOpenStruct.load(hash)
82
+ assert_equal "blah", deepstruct.type
83
+ end
84
+
85
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepopenstruct
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Aaron Gough
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-04 00:00:00 -04:00
17
+ date: 2010-08-23 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -49,27 +48,23 @@ rdoc_options:
49
48
  require_paths:
50
49
  - lib
51
50
  required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
51
  requirements:
54
52
  - - ">="
55
53
  - !ruby/object:Gem::Version
56
- hash: 3
57
54
  segments:
58
55
  - 0
59
56
  version: "0"
60
57
  required_rubygems_version: !ruby/object:Gem::Requirement
61
- none: false
62
58
  requirements:
63
59
  - - ">="
64
60
  - !ruby/object:Gem::Version
65
- hash: 3
66
61
  segments:
67
62
  - 0
68
63
  version: "0"
69
64
  requirements: []
70
65
 
71
66
  rubyforge_project:
72
- rubygems_version: 1.3.7
67
+ rubygems_version: 1.3.6
73
68
  signing_key:
74
69
  specification_version: 3
75
70
  summary: A simple library for creating easy-to-use data structures from complex sets of nested Hashes and Arrays