blizz 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +24 -1
- data/lib/blizz.rb +14 -8
- metadata +1 -1
data/Readme.md
CHANGED
@@ -21,4 +21,27 @@ Simple isn't it?
|
|
21
21
|
Useful for prototyping domain models, DDD, etc :)
|
22
22
|
|
23
23
|
|
24
|
-
|
24
|
+
## more...
|
25
|
+
|
26
|
+
### load array of hases
|
27
|
+
|
28
|
+
load arrays of hashes, give them a :type and watch how Blizz casts them to classes!
|
29
|
+
|
30
|
+
### partial loading
|
31
|
+
|
32
|
+
load only some properties of the hash in to the classs selectively
|
33
|
+
|
34
|
+
example:
|
35
|
+
|
36
|
+
```
|
37
|
+
example = Blizz.load Example, hash, [:a]
|
38
|
+
```
|
39
|
+
|
40
|
+
will load `a: "b"` but not `c: "d"`
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
have fun!
|
47
|
+
@makevoid
|
data/lib/blizz.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Blizz
|
2
2
|
|
3
|
-
VERSION = "0.
|
3
|
+
VERSION = "0.2"
|
4
4
|
|
5
|
-
def self.load(klass, hash)
|
5
|
+
def self.load(klass, hash, selection=nil)
|
6
6
|
page = klass.new
|
7
|
-
page.load hash
|
7
|
+
page.load hash, selection
|
8
8
|
page
|
9
9
|
end
|
10
10
|
|
@@ -14,9 +14,9 @@ class Blizz
|
|
14
14
|
self.class
|
15
15
|
end
|
16
16
|
|
17
|
-
def load(hash)
|
17
|
+
def load(hash, selection)
|
18
18
|
klass.create_accessors hash
|
19
|
-
load_contents hash
|
19
|
+
load_contents hash, selection
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.included(mod)
|
@@ -31,8 +31,10 @@ class Blizz
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
def load_contents(hash)
|
34
|
+
def load_contents(hash, selection)
|
35
35
|
hash.map do |key, val|
|
36
|
+
next if selection && !selection.include?(key.to_sym)
|
37
|
+
|
36
38
|
if array_of_hashes? val
|
37
39
|
val = replace_contents val
|
38
40
|
end
|
@@ -47,8 +49,12 @@ class Blizz
|
|
47
49
|
|
48
50
|
def replace_contents(array)
|
49
51
|
array.map do |hash|
|
50
|
-
|
51
|
-
|
52
|
+
if hash[:type]
|
53
|
+
klass = Object.const_get hash[:type]
|
54
|
+
Blizz.load klass, hash
|
55
|
+
else
|
56
|
+
hash
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|