transcriber 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/initialize/embeds_many.rb +26 -0
- data/examples/initialize/embeds_one.rb +20 -0
- data/examples/initialize/simple.rb +10 -0
- data/lib/transcriber/resource/key/association.rb +6 -0
- data/lib/transcriber/resource/key/embeddable.rb +5 -0
- data/lib/transcriber/resource/key/property.rb +4 -0
- data/lib/transcriber/resource.rb +5 -1
- data/lib/transcriber/version.rb +1 -1
- metadata +16 -13
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Customer < Transcriber::Resource
|
4
|
+
property :name
|
5
|
+
embeds_many :phones
|
6
|
+
end
|
7
|
+
|
8
|
+
class Phone < Transcriber::Resource
|
9
|
+
properties :number, :extension
|
10
|
+
end
|
11
|
+
|
12
|
+
@root = Customer.new({
|
13
|
+
name: "Jackie Chan",
|
14
|
+
phones: [
|
15
|
+
{
|
16
|
+
number: "2980319083",
|
17
|
+
extension: "1398"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
number: "2979139332",
|
21
|
+
extension: "1011"
|
22
|
+
}
|
23
|
+
]})
|
24
|
+
|
25
|
+
puts "root: #{@root.inspect}"
|
26
|
+
puts "resource: #{@root.resource}"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push 'lib'; require 'transcriber'
|
2
|
+
|
3
|
+
class Customer < Transcriber::Resource
|
4
|
+
property :name
|
5
|
+
embeds_one :address
|
6
|
+
end
|
7
|
+
|
8
|
+
class Address < Transcriber::Resource
|
9
|
+
properties :street, :number
|
10
|
+
end
|
11
|
+
|
12
|
+
@root = Customer.new({
|
13
|
+
name: "Jackie Chan",
|
14
|
+
address: {
|
15
|
+
street: "Aurora St",
|
16
|
+
number: 666
|
17
|
+
}})
|
18
|
+
|
19
|
+
puts "root: #{@root.inspect}"
|
20
|
+
puts "resource: #{@root.resource}"
|
@@ -24,6 +24,12 @@ module Transcriber
|
|
24
24
|
def resource_class
|
25
25
|
@class_name.constantize
|
26
26
|
end
|
27
|
+
|
28
|
+
def from_hash(attrs)
|
29
|
+
return nil if attrs.nil? or attrs.empty?
|
30
|
+
one? ? resource_class.new(attrs)
|
31
|
+
: Array(attrs).map {|item| resource_class.new(item)}
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/transcriber/resource.rb
CHANGED
@@ -9,7 +9,11 @@ module Transcriber
|
|
9
9
|
cattr_writer :resource_name
|
10
10
|
|
11
11
|
def initialize(attrs = {})
|
12
|
-
attrs.
|
12
|
+
return if attrs.nil? or attrs.empty?
|
13
|
+
|
14
|
+
self.class.keys.each do |key|
|
15
|
+
__send__("#{key.name}=", key.from_hash(attrs[key.name])) if key.present? self
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def self.keys
|
data/lib/transcriber/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transcriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2011-08-29 00:00:00.000000000Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
|
-
requirement: &
|
18
|
+
requirement: &70363203539880 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70363203539880
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: i18n
|
29
|
-
requirement: &
|
29
|
+
requirement: &70363203539360 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0.5'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70363203539360
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &70363203538900 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '2.6'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70363203538900
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: guard
|
51
|
-
requirement: &
|
51
|
+
requirement: &70363203538440 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: '0.5'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *70363203538440
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: guard-rspec
|
62
|
-
requirement: &
|
62
|
+
requirement: &70363203537960 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0.4'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *70363203537960
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: growl
|
73
|
-
requirement: &
|
73
|
+
requirement: &70363203537480 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ~>
|
@@ -78,7 +78,7 @@ dependencies:
|
|
78
78
|
version: '1.0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *70363203537480
|
82
82
|
description: ''
|
83
83
|
email:
|
84
84
|
- victorcrodrigues@gmail.com
|
@@ -107,6 +107,9 @@ files:
|
|
107
107
|
- examples/embeds_one/with_if.rb
|
108
108
|
- examples/embeds_one/with_start_key.rb
|
109
109
|
- examples/has_many/simple.rb
|
110
|
+
- examples/initialize/embeds_many.rb
|
111
|
+
- examples/initialize/embeds_one.rb
|
112
|
+
- examples/initialize/simple.rb
|
110
113
|
- examples/properties/array_serialization.rb
|
111
114
|
- examples/properties/collections.rb
|
112
115
|
- examples/properties/simple.rb
|