phantom-object 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/README.rdoc +48 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 899e827016c6981c42fac70e59e5b65046b52a9a
|
4
|
+
data.tar.gz: 900ac7cf818d09056bf334723852c87c993aa2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8f1dcd39e49d401be9811ba2ffc72f7f2a661eb94b62fb5c472460e22cd91acb49c5571c2fa4a486dca6edcc7c6aece035786d4e907e05a3ced0c44a9fd9373
|
7
|
+
data.tar.gz: 5d1056855c41556b06f5c32a9e87bbe448170cb10e425fdc61c0c13c4c45f82cdd81b14dc2d07176393d0a2170ff1720d11dc7c1e97b7d240305ef7b14530224
|
data/README.rdoc
CHANGED
@@ -1,5 +1,52 @@
|
|
1
1
|
= A Hash to object converter
|
2
2
|
|
3
|
+
Allows you to convert complex Hashes into objects for more common use.
|
4
|
+
|
3
5
|
In your Gemfile, make sure you have this gem:
|
4
6
|
|
5
|
-
gem 'phantom-object'
|
7
|
+
gem 'phantom-object'
|
8
|
+
|
9
|
+
Now you can do this
|
10
|
+
|
11
|
+
h = {
|
12
|
+
key: "Some value",
|
13
|
+
another_key: "Another value"
|
14
|
+
}
|
15
|
+
|
16
|
+
o = PhantomObject.new(h)
|
17
|
+
|
18
|
+
p h.key
|
19
|
+
# => "Some value"
|
20
|
+
p h.another_key
|
21
|
+
# => "Some value"
|
22
|
+
|
23
|
+
And even this
|
24
|
+
|
25
|
+
h = {
|
26
|
+
nested: {
|
27
|
+
key: "Some value"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
o = PhantomObject.new(h)
|
32
|
+
|
33
|
+
p h.nested.key
|
34
|
+
# => "Some value"
|
35
|
+
|
36
|
+
For any level, and with arrays
|
37
|
+
|
38
|
+
And also you can do this, instead of PhantomObject.new()
|
39
|
+
|
40
|
+
h = {
|
41
|
+
key: "Some value",
|
42
|
+
another_key: "Another value"
|
43
|
+
}
|
44
|
+
|
45
|
+
o = h.to_object
|
46
|
+
|
47
|
+
p h.key
|
48
|
+
# => "Some value"
|
49
|
+
p h.another_key
|
50
|
+
# => "Some value"
|
51
|
+
|
52
|
+
Also, PhantomObject includes ActiveModel, and you can extend it to use validations, form builders, etc.
|