odm 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -9
- data/VERSION +1 -1
- data/examples/test.rb +2 -10
- data/lib/odm.rb +6 -6
- data/odm.gemspec +2 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d0492cc264952b0257f26144c4d44845b4e4772
|
4
|
+
data.tar.gz: 67517e6cf32613e3b19c3533fa17fd10f566be68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd7befd4a122576f1ba3ea5a6c8d9572f6faf300d6cb4fef551832c9c3ea6c887c5883a8370d84134c2a74459a4a86a1e34ef0e8b4159515e2ca7d26674492f
|
7
|
+
data.tar.gz: a13ddc9a3d73eb680763402b618e3862cd3eccc91ef2c123c8e62f7e6cbc59cfd89d66700a76ceef6231800868e4e0b59e83c9197f09e0a38e6beae93273e45b
|
data/README.md
CHANGED
@@ -5,28 +5,34 @@ Simple Object Data Mapper
|
|
5
5
|
|
6
6
|
Parse Array of Hash into random Class of classes to make it more object oriented on the fly :)
|
7
7
|
|
8
|
+
at this point the following classes (and they child's) are implemented:
|
9
|
+
* [ Module, Array, Hash, Regexp, String, File, IO ]
|
10
|
+
|
11
|
+
initialize method will be called directly in array and hash classes,
|
12
|
+
but will be exception handled if Argument or NoMethod Error occurs
|
13
|
+
|
8
14
|
### example
|
9
15
|
|
10
16
|
```ruby
|
11
17
|
|
12
18
|
require 'odm'
|
13
19
|
|
14
|
-
class
|
20
|
+
#> some random class as target models
|
15
21
|
|
22
|
+
class STRING < String
|
23
|
+
end
|
24
|
+
|
25
|
+
class ARRAY < Array
|
16
26
|
end
|
17
27
|
|
18
28
|
class HASH < Hash
|
19
29
|
|
20
30
|
def initialize original_obj
|
21
|
-
# some stuff on init
|
31
|
+
# some stuff on init for fun
|
22
32
|
end
|
23
33
|
|
24
34
|
end
|
25
35
|
|
26
|
-
class STRING < String
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
36
|
odm= ODM.new do |opts|
|
31
37
|
opts.array = ARRAY
|
32
38
|
opts.hash = HASH
|
@@ -35,9 +41,7 @@ Parse Array of Hash into random Class of classes to make it more object oriented
|
|
35
41
|
|
36
42
|
var= odm.parse [ {hello: {"world" => "hey!"} }, 123 ]
|
37
43
|
puts var.inspect,var.class,var[0].class,var[0][:hello].keys[0].class
|
38
|
-
#> ARRAY
|
39
|
-
#> HASH
|
40
|
-
#> STRING
|
44
|
+
#> [{:hello=>{"world"=>"hey!"}}, 123], ARRAY, HASH, STRING
|
41
45
|
|
42
46
|
```
|
43
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/examples/test.rb
CHANGED
@@ -1,32 +1,24 @@
|
|
1
1
|
require_relative "../lib/odm"
|
2
2
|
|
3
3
|
class ARRAY < Array
|
4
|
-
|
5
4
|
end
|
6
5
|
|
7
6
|
class HASH < Hash
|
8
|
-
|
9
|
-
def initialize obj
|
10
|
-
# puts obj
|
11
|
-
end
|
12
|
-
|
13
7
|
end
|
14
8
|
|
15
9
|
class STRING < String
|
16
|
-
|
17
10
|
end
|
18
11
|
|
19
12
|
odm= ODM.new do |opts|
|
20
13
|
opts.array = ARRAY
|
21
14
|
opts.hash = HASH
|
22
15
|
opts.string = STRING
|
23
|
-
opts.symbol = SYMBOL
|
24
16
|
end
|
25
17
|
|
26
18
|
var= odm.parse [ {hello: {"world" => "hey!"} }, 123 ]
|
27
|
-
puts var.
|
19
|
+
puts [var.class,var[0].class,var[0][:hello].keys[0].class].join(', ')
|
28
20
|
|
29
21
|
require 'yaml'
|
30
22
|
yaml_data= [ {hello: {"world" => "hey!"} }, 123 ].to_yaml
|
31
23
|
|
32
|
-
|
24
|
+
odm.parse_yml(yaml_data).inspect
|
data/lib/odm.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mpatch'
|
2
|
-
|
3
1
|
module ODM
|
4
2
|
|
5
3
|
CoreClasses= [ ::Module, ::Array, ::Hash, ::Regexp, ::String, ::File, ::IO ] #> Fixnum, Float, Integer dont have .new
|
@@ -39,7 +37,7 @@ module ODM
|
|
39
37
|
|
40
38
|
define_method(core_class.to_s.downcase+"=") do |klass|
|
41
39
|
raise(ArgumentError,"Invalid object for class: #{klass}") unless klass.class == ::Class
|
42
|
-
raise(ArgumentError,"Invalid parse class: #{klass}")
|
40
|
+
raise(ArgumentError,"Invalid parse class: #{klass}, must be or subclass of the #{core_class} class") unless klass <= core_class
|
43
41
|
self.instance_variable_set( "@#{core_class.to_s.downcase}", klass )
|
44
42
|
end
|
45
43
|
|
@@ -70,10 +68,12 @@ module ODM
|
|
70
68
|
case ODM::Helper.class?( obj.class ).to_s.downcase.to_sym
|
71
69
|
|
72
70
|
when :array
|
73
|
-
|
71
|
+
var= @class.__send__(ODM::Helper.class?( obj.class ).to_s.downcase)[ *obj.map!{ |e| self.parse!(e) } ]
|
72
|
+
begin; var.__send__( :initialize, obj ) ;rescue ::NoMethodError,::ArgumentError ;end
|
73
|
+
return var
|
74
74
|
|
75
75
|
when :hash
|
76
|
-
var= @class.__send__(ODM::Helper.class?( obj.class ).to_s.downcase)[ obj.
|
76
|
+
var= @class.__send__(ODM::Helper.class?( obj.class ).to_s.downcase)[ *obj.map{ |k,v| { self.parse!(k) => self.parse!(v) } } ]
|
77
77
|
begin; var.__send__( :initialize, obj ) ;rescue ::NoMethodError,::ArgumentError ;end
|
78
78
|
return var
|
79
79
|
|
@@ -85,7 +85,7 @@ module ODM
|
|
85
85
|
return obj if klass.nil?
|
86
86
|
return klass.new(obj)
|
87
87
|
|
88
|
-
rescue ::NoMethodError
|
88
|
+
rescue ::NoMethodError, ::ArgumentError
|
89
89
|
return obj
|
90
90
|
end
|
91
91
|
|
data/odm.gemspec
CHANGED
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.2.0
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mpatch
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.12.1
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.12.1
|
55
41
|
description: " Simple Object Data Mapper. Parse Array of Hash into random Class of
|
56
42
|
classes to make it more object oriented "
|
57
43
|
email:
|