odm 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -4
- data/VERSION +1 -1
- data/examples/level.rb +10 -3
- data/lib/odm.rb +18 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7f5556d02049a79c19e2105f6314c64cfdd55c6
|
4
|
+
data.tar.gz: c86f577670bada50d796a1f2857bb46463c339e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ebfb8dd144fb11d8274f88a1d2fb0db3222c05f76fa7dbb304850d567a78e86c101a15a4cbc8be86f54e0596cd8a87c78ac6bafec9e99350a087830b4e78c02
|
7
|
+
data.tar.gz: 37e8700f3c6348fb52be92ac3a60b1804b2b3ee9bfa92c9b73fde5c02189c13324283aa1efda06c11e0c17429b6d065caeae94a890bd7e21e7bfcbcec2ea2f2e
|
data/README.md
CHANGED
@@ -3,7 +3,9 @@ ODM
|
|
3
3
|
|
4
4
|
Simple Object Data Mapper
|
5
5
|
|
6
|
-
Parse Array of Hash into
|
6
|
+
Parse Array of Hash or any complex object into subclass of the main ones to make it more object oriented on the fly :)
|
7
|
+
Why? Because you can make scopes like that to incoming datas like json.
|
8
|
+
And with that you can have random methods on the objects without the need of analyze the data :)
|
7
9
|
|
8
10
|
at this point the following classes (and they child's) are implemented:
|
9
11
|
* [ Module, Array, Hash, Regexp, String, File, IO ]
|
@@ -58,10 +60,18 @@ we can simply pass to opts the defaults we want to be used when the parser find
|
|
58
60
|
class ARRAY2 < Array
|
59
61
|
end
|
60
62
|
|
61
|
-
|
62
|
-
odm= ODM.new( { array: ARRAY1 }, { array: ARRAY2 }, [:var,"hello"] ) do |opts|
|
63
|
+
odm= ODM.new(
|
63
64
|
|
64
|
-
|
65
|
+
# defaults for deepness level 0
|
66
|
+
{ array: ARRAY1 },
|
67
|
+
|
68
|
+
# defaults for deepness level 1
|
69
|
+
{ array: ARRAY2 },
|
70
|
+
|
71
|
+
# default instance variables to be set for each object
|
72
|
+
[:var,"hello"] ) do |opts|
|
73
|
+
|
74
|
+
# defaults for else places (if no target class given,than no parse will be made)
|
65
75
|
opts.array= ARRAYDEF
|
66
76
|
|
67
77
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.1
|
data/examples/level.rb
CHANGED
@@ -9,15 +9,22 @@ end
|
|
9
9
|
class ARRAY2 < Array
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
odm= ODM.new(
|
13
|
+
|
14
|
+
# defaults for deepness level 0
|
15
|
+
{ array: ARRAY1 },
|
16
|
+
|
17
|
+
# defaults for deepness level 1
|
18
|
+
{ array: ARRAY2 },
|
19
|
+
|
20
|
+
# default instance variables to be set for each object
|
21
|
+
[:var,"hello"] ) do |opts|
|
14
22
|
|
15
23
|
# defaults for else places (if block not given, no parse will be made)
|
16
24
|
opts.array= ARRAYDEF
|
17
25
|
|
18
26
|
end
|
19
27
|
|
20
|
-
|
21
28
|
obj= [[[]]]
|
22
29
|
var= odm.parse obj
|
23
30
|
puts odm.state
|
data/lib/odm.rb
CHANGED
@@ -28,6 +28,14 @@ module ODM
|
|
28
28
|
return nil
|
29
29
|
end
|
30
30
|
|
31
|
+
def array_to_hash_merge_parser(klass,array)
|
32
|
+
|
33
|
+
var= klass.new
|
34
|
+
array.each{|hash| var.merge!(hash) }
|
35
|
+
return var
|
36
|
+
|
37
|
+
end
|
38
|
+
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
@@ -133,20 +141,27 @@ module ODM
|
|
133
141
|
var.instance_variable_set( "@#{ary[0]}",ary[1] )
|
134
142
|
end
|
135
143
|
|
136
|
-
var #> return
|
144
|
+
var #> return and shift down level
|
137
145
|
end
|
138
146
|
|
139
147
|
when :hash
|
140
148
|
|
141
149
|
klass= get_class.call(obj)
|
142
150
|
return level do
|
143
|
-
|
151
|
+
|
152
|
+
var= nil
|
153
|
+
begin
|
154
|
+
var= obj.map{ |k,v| { self.parse(k) => self.parse(v) } }
|
155
|
+
var= klass[ *var ]
|
156
|
+
rescue ArgumentError
|
157
|
+
var= ODM::Helper.array_to_hash_merge_parser(klass,var)
|
158
|
+
end
|
144
159
|
|
145
160
|
@instance_variables.each do |ary|
|
146
161
|
var.instance_variable_set( "@#{ary[0]}",ary[1] )
|
147
162
|
end
|
148
163
|
|
149
|
-
var #> return
|
164
|
+
var #> return and shift down level
|
150
165
|
end
|
151
166
|
|
152
167
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|