transcriber 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require 'json'
2
+
3
+ $:.push 'lib'; require 'transcriber'
4
+
5
+ class Root < Transcriber::Resource
6
+ embeds_many :items, class_name: "Array"
7
+ end
8
+
9
+ @root = Root.new
10
+ @root.items = ["a", "b"]
11
+
12
+ puts "resource: #{@root.resource}"
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+
3
+ $:.push 'lib'; require 'transcriber'
4
+
5
+ class Item < Transcriber::Resource
6
+ property :id
7
+ end
8
+
9
+ class Root < Transcriber::Resource
10
+ embeds_many :items
11
+ end
12
+
13
+ @root = Root.new
14
+
15
+ puts "resource: #{@root.resource}"
@@ -43,7 +43,7 @@ module Transcriber
43
43
  end
44
44
 
45
45
  def self.not_allowed_names
46
- ["resource_id", "resource", "link"]
46
+ %w(resource_id resource link)
47
47
  end
48
48
  end
49
49
  end
@@ -3,6 +3,10 @@ module Transcriber
3
3
  class Embeddable < Association
4
4
  include Parser::Embeddable
5
5
  include Response::Embeddable
6
+
7
+ def raw?
8
+ ![Hash, Array].include?(resource_class)
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -3,15 +3,9 @@ module Transcriber
3
3
  module Parser
4
4
  module Embeddable
5
5
  def parse(value, resource = nil)
6
- parsed_value = parse? ? resource_class.parse(value) : value
6
+ parsed_value = raw? ? resource_class.parse(value) : value
7
7
  one? ? parsed_value.first : parsed_value
8
8
  end
9
-
10
- private
11
-
12
- def parse?
13
- ![Hash, Array].include?(resource_class)
14
- end
15
9
  end
16
10
  end
17
11
  end
@@ -8,13 +8,19 @@ module Transcriber
8
8
  resource = nil
9
9
 
10
10
  if embedded = parent.__send__(name)
11
- resource = one? ? embedded.resource : embedded.map(&:resource)
11
+ resource = raw? ? resourcify(embedded) : embedded
12
12
  elsif many?
13
13
  resource = []
14
14
  end
15
15
 
16
16
  {name => resource}
17
17
  end
18
+
19
+ private
20
+
21
+ def resourcify(embedded)
22
+ one? ? embedded.resource : embedded.map(&:resource)
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module Transcriber
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
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.5
4
+ version: 0.0.6
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-26 00:00:00.000000000Z
14
+ date: 2011-08-29 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70255548632660 !ruby/object:Gem::Requirement
18
+ requirement: &70312532176600 !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: *70255548632660
26
+ version_requirements: *70312532176600
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: i18n
29
- requirement: &70255548632020 !ruby/object:Gem::Requirement
29
+ requirement: &70312532176100 !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: *70255548632020
37
+ version_requirements: *70312532176100
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec
40
- requirement: &70255548631460 !ruby/object:Gem::Requirement
40
+ requirement: &70312532175640 !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: *70255548631460
48
+ version_requirements: *70312532175640
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: guard
51
- requirement: &70255548630900 !ruby/object:Gem::Requirement
51
+ requirement: &70312532175160 !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: *70255548630900
59
+ version_requirements: *70312532175160
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: guard-rspec
62
- requirement: &70255548630300 !ruby/object:Gem::Requirement
62
+ requirement: &70312532174660 !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: *70255548630300
70
+ version_requirements: *70312532174660
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: growl
73
- requirement: &70255548629820 !ruby/object:Gem::Requirement
73
+ requirement: &70312532174180 !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: *70255548629820
81
+ version_requirements: *70312532174180
82
82
  description: ''
83
83
  email:
84
84
  - victorcrodrigues@gmail.com
@@ -96,8 +96,10 @@ files:
96
96
  - examples/all.rb
97
97
  - examples/embeds_many/invisible.rb
98
98
  - examples/embeds_many/simple.rb
99
+ - examples/embeds_many/with_array.rb
99
100
  - examples/embeds_many/with_class_name.rb
100
101
  - examples/embeds_many/with_if.rb
102
+ - examples/embeds_many/with_nil_value.rb
101
103
  - examples/embeds_many/with_start_key.rb
102
104
  - examples/embeds_one/simple.rb
103
105
  - examples/embeds_one/with_class_name.rb