hash_to_object 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +10 -2
- data/README.md +46 -14
- data/hash_to_object.gemspec +6 -33
- metadata +12 -13
data/Gemfile.lock
CHANGED
@@ -5,11 +5,19 @@ PATH
|
|
5
5
|
|
6
6
|
GEM
|
7
7
|
specs:
|
8
|
-
|
8
|
+
diff-lcs (1.1.3)
|
9
|
+
rspec (2.6.0)
|
10
|
+
rspec-core (~> 2.6.0)
|
11
|
+
rspec-expectations (~> 2.6.0)
|
12
|
+
rspec-mocks (~> 2.6.0)
|
13
|
+
rspec-core (2.6.4)
|
14
|
+
rspec-expectations (2.6.0)
|
15
|
+
diff-lcs (~> 1.1.2)
|
16
|
+
rspec-mocks (2.6.0)
|
9
17
|
|
10
18
|
PLATFORMS
|
11
19
|
ruby
|
12
20
|
|
13
21
|
DEPENDENCIES
|
14
22
|
hash_to_object!
|
15
|
-
rspec
|
23
|
+
rspec (~> 2.3)
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
HashToObject
|
2
2
|
============
|
3
3
|
|
4
|
-
HashToObject is a mixin for converting hashes into ruby objects. For instance, if you wanted
|
4
|
+
HashToObject is a mixin for converting hashes into ruby objects. For instance, if you wanted to build Foo objects, you could define it as such:
|
5
5
|
|
6
|
-
class
|
6
|
+
class Foo
|
7
7
|
include HashToObject
|
8
8
|
|
9
9
|
def initialize(options = {})
|
@@ -11,20 +11,52 @@ HashToObject is a mixin for converting hashes into ruby objects. For instance,
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
You can now build new Foo objects with arbitrary key value pairs and have access to them.
|
15
|
+
|
16
|
+
foo = Foo.new('bar' => 'baz', 'qux' => [1,2,3])
|
17
|
+
|
18
|
+
foo.bar
|
19
|
+
=> "baz"
|
20
|
+
foo.bar = "garply"
|
21
|
+
=> "garply"
|
22
|
+
|
23
|
+
quux = Foo.new('corge' => 'grault')
|
24
|
+
|
25
|
+
quux.bar
|
26
|
+
=> NoMethodError: undefined method 'bar'
|
27
|
+
quux.corge
|
28
|
+
=> "grault"
|
29
|
+
|
30
|
+
|
31
|
+
Recursion and Nesting
|
32
|
+
=====================
|
33
|
+
HashToObject also supports nesting of object creation. Note that you will need classes that correspond to the hash structure.
|
34
|
+
|
35
|
+
class Foo::Item
|
36
|
+
include HashToObject
|
19
37
|
|
20
|
-
|
21
|
-
|
22
|
-
|
38
|
+
def initialize(options = {})
|
39
|
+
objectify(options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Foo::Lolipop
|
44
|
+
include HashToObject
|
23
45
|
|
24
|
-
|
46
|
+
def initialize(options = {})
|
47
|
+
objectify(options)
|
48
|
+
end
|
25
49
|
|
26
|
-
|
50
|
+
def waldo
|
51
|
+
"Where in the world is #{@id}?"
|
52
|
+
end
|
53
|
+
end
|
27
54
|
|
28
|
-
|
55
|
+
foo = Foo.new('item' => {'name' => 'foo'}, 'lolipops' => [{'id'=> 'bar'}, {'id'=> 'baz'}])
|
29
56
|
|
30
|
-
|
57
|
+
foo.item
|
58
|
+
=> #<Foo::Item:0x007fbf40ee1e78 @name="foo">
|
59
|
+
foo.lolipops
|
60
|
+
=> [#<Foo::Lolipop:0x007fbf429d4780 @id="bar">, #<Foo::Lolipop:0x007fbf42bc1a48 @id="baz">]
|
61
|
+
foo.lolipops.first.waldo
|
62
|
+
=> "Where in the world is bar?"
|
data/hash_to_object.gemspec
CHANGED
@@ -1,44 +1,19 @@
|
|
1
|
-
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
-
## all of the comments. Some sections require modification, and others can
|
3
|
-
## be deleted if you don't need them. Once you understand the contents of
|
4
|
-
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
-
## You can find comprehensive Gem::Specification documentation, at
|
6
|
-
## http://docs.rubygems.org/read/chapter/20
|
7
1
|
Gem::Specification.new do |s|
|
8
2
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
4
|
s.rubygems_version = '1.3.5'
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
16
|
-
s.version = '0.1.0'
|
17
|
-
s.date = '2011-09-26'
|
18
|
-
|
19
|
-
## Make sure your summary is short. The description may be as long
|
20
|
-
## as you like.
|
21
|
-
s.summary = "Converts json-like hashes into ruby objects."
|
22
|
-
s.description = ""
|
23
|
-
|
24
|
-
## List the primary authors. If there are a bunch of authors, it's probably
|
25
|
-
## better to set the email to an email list or something. If you don't have
|
26
|
-
## a custom homepage, consider using your GitHub URL or the like.
|
6
|
+
s.name = 'hash_to_object'
|
7
|
+
s.version = '0.1.1'
|
8
|
+
s.date = '2011-09-26'
|
9
|
+
s.summary = "Converts hashes into ruby objects."
|
27
10
|
s.authors = ["Phillip Birtcher"]
|
28
11
|
s.email = 'philbirt@gmail.com'
|
29
12
|
s.homepage = 'https://github.com/philbirt/hash_to_object'
|
30
|
-
|
31
|
-
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
32
|
-
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
33
13
|
s.require_paths = %w[lib]
|
14
|
+
|
15
|
+
s.add_development_dependency('rspec', "~> 2.3")
|
34
16
|
|
35
|
-
## List your development dependencies here. Development dependencies are
|
36
|
-
## those that are only needed during development
|
37
|
-
s.add_development_dependency('rspec')
|
38
|
-
|
39
|
-
## Leave this section as-is. It will be automatically generated from the
|
40
|
-
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
41
|
-
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
42
17
|
# = MANIFEST =
|
43
18
|
s.files = %w[
|
44
19
|
Gemfile
|
@@ -51,7 +26,5 @@ Gem::Specification.new do |s|
|
|
51
26
|
]
|
52
27
|
# = MANIFEST =
|
53
28
|
|
54
|
-
## Test files will be grabbed from the file list. Make sure the path glob
|
55
|
-
## matches what you actually use.
|
56
29
|
s.test_files = s.files.select { |path| path =~ /^spec\/*._spec\.rb/ }
|
57
30
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_to_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Phillip Birtcher
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-26 00:00:00
|
19
|
-
default_executable:
|
18
|
+
date: 2011-09-26 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rspec
|
@@ -24,15 +23,16 @@ dependencies:
|
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
|
-
- -
|
26
|
+
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 5
|
30
29
|
segments:
|
31
|
-
-
|
32
|
-
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
version: "2.3"
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
|
-
description:
|
35
|
+
description:
|
36
36
|
email: philbirt@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- hash_to_object.gemspec
|
49
49
|
- lib/hash_to_object.rb
|
50
50
|
- spec/hash_to_object_spec.rb
|
51
|
-
has_rdoc: true
|
52
51
|
homepage: https://github.com/philbirt/hash_to_object
|
53
52
|
licenses: []
|
54
53
|
|
@@ -78,9 +77,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
77
|
requirements: []
|
79
78
|
|
80
79
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.8.21
|
82
81
|
signing_key:
|
83
82
|
specification_version: 2
|
84
|
-
summary: Converts
|
83
|
+
summary: Converts hashes into ruby objects.
|
85
84
|
test_files: []
|
86
85
|
|