transcriber 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ $:.push 'lib'; require 'transcriber'
2
+
3
+ class Customer < Transcriber::Resource
4
+ property :products, type: Enumerable
5
+ end
6
+
7
+ @root = Customer.parse({'products' => ['a', 'b', 'c']}).first
8
+
9
+ puts "root: #{@root.inspect}"
10
+ puts "resource: #{@root.resource}"
data/lib/transcriber.rb CHANGED
@@ -11,6 +11,7 @@ require 'transcriber/resource/parser'
11
11
  require 'transcriber/resource/response'
12
12
  require 'transcriber/resource/serialization/boolean'
13
13
  require 'transcriber/resource/serialization/date'
14
+ require 'transcriber/resource/serialization/enumerable'
14
15
  require 'transcriber/resource/serialization/float'
15
16
  require 'transcriber/resource/serialization/integer'
16
17
  require 'transcriber/resource/serialization/string'
@@ -4,8 +4,15 @@ module Transcriber
4
4
  module Embeddable
5
5
  def to_resource(parent)
6
6
  return {} unless visible?(parent)
7
- embedded = parent.__send__(name)
8
- resource = one? ? embedded.resource : embedded.map(&:resource)
7
+
8
+ resource = nil
9
+
10
+ if embedded = parent.__send__(name)
11
+ resource = one? ? embedded.resource : embedded.map(&:resource)
12
+ elsif many?
13
+ resource = []
14
+ end
15
+
9
16
  {name => resource}
10
17
  end
11
18
  end
@@ -0,0 +1,12 @@
1
+ module Transcriber
2
+ class Resource
3
+ module Serialization
4
+ class Enumerable
5
+ def self.serialize(value)
6
+ fail "value not serializable: #{value}" unless value.kind_of?(::Enumerable)
7
+ value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-23 00:00:00.000000000Z
14
+ date: 2011-08-26 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70173958045380 !ruby/object:Gem::Requirement
18
+ requirement: &70255548632660 !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: *70173958045380
26
+ version_requirements: *70255548632660
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70173958044880 !ruby/object:Gem::Requirement
29
+ requirement: &70255548632020 !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: *70173958044880
37
+ version_requirements: *70255548632020
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70173958044420 !ruby/object:Gem::Requirement
40
+ requirement: &70255548631460 !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: *70173958044420
48
+ version_requirements: *70255548631460
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70173958043920 !ruby/object:Gem::Requirement
51
+ requirement: &70255548630900 !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: *70173958043920
59
+ version_requirements: *70255548630900
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70173958043460 !ruby/object:Gem::Requirement
62
+ requirement: &70255548630300 !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: *70173958043460
70
+ version_requirements: *70255548630300
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70173958043000 !ruby/object:Gem::Requirement
73
+ requirement: &70255548629820 !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: *70173958043000
81
+ version_requirements: *70255548629820
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com
@@ -104,6 +104,7 @@ files:
104
104
  - examples/embeds_one/with_if.rb
105
105
  - examples/embeds_one/with_start_key.rb
106
106
  - examples/has_many/simple.rb
107
+ - examples/properties/array_serialization.rb
107
108
  - examples/properties/collections.rb
108
109
  - examples/properties/simple.rb
109
110
  - examples/properties/with_field.rb
@@ -139,6 +140,7 @@ files:
139
140
  - lib/transcriber/resource/response/relation.rb
140
141
  - lib/transcriber/resource/serialization/boolean.rb
141
142
  - lib/transcriber/resource/serialization/date.rb
143
+ - lib/transcriber/resource/serialization/enumerable.rb
142
144
  - lib/transcriber/resource/serialization/float.rb
143
145
  - lib/transcriber/resource/serialization/integer.rb
144
146
  - lib/transcriber/resource/serialization/string.rb