transcriber 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/.gitignore +1 -0
  2. data/Guardfile +7 -0
  3. data/README.md +39 -0
  4. data/examples/all.rb +14 -0
  5. data/examples/embeds_many/simple.rb +14 -0
  6. data/examples/embeds_many/with_class_name.rb +14 -0
  7. data/examples/embeds_many/with_if.rb +21 -0
  8. data/examples/embeds_many/with_start_key.rb +17 -0
  9. data/examples/embeds_one/simple.rb +14 -0
  10. data/examples/embeds_one/with_class_name.rb +14 -0
  11. data/examples/embeds_one/with_if.rb +21 -0
  12. data/examples/embeds_one/with_start_key.rb +14 -0
  13. data/examples/has_many/simple.rb +29 -0
  14. data/examples/properties/simple.rb +10 -0
  15. data/examples/properties/with_field.rb +10 -0
  16. data/examples/properties/with_field_path.rb +10 -0
  17. data/examples/properties/with_id.rb +10 -0
  18. data/examples/properties/with_if.rb +19 -0
  19. data/examples/properties/with_key_converter.rb +20 -0
  20. data/lib/transcriber/configuration.rb +13 -0
  21. data/lib/transcriber/resource/builder/embeddables.rb +21 -0
  22. data/lib/transcriber/resource/builder/keys.rb +20 -0
  23. data/lib/transcriber/resource/builder/properties.rb +29 -0
  24. data/lib/transcriber/resource/builder/relations.rb +26 -0
  25. data/lib/transcriber/resource/builder/summarizations.rb +14 -0
  26. data/lib/transcriber/resource/builder.rb +10 -0
  27. data/lib/transcriber/resource/input_path.rb +19 -0
  28. data/lib/transcriber/resource/key/association.rb +29 -0
  29. data/lib/transcriber/resource/key/embeddable.rb +8 -0
  30. data/lib/transcriber/resource/key/property.rb +17 -0
  31. data/lib/transcriber/resource/key/relation.rb +24 -0
  32. data/lib/transcriber/resource/key.rb +29 -0
  33. data/lib/transcriber/resource/parser/embeddable.rb +12 -0
  34. data/lib/transcriber/resource/parser/property.rb +15 -0
  35. data/lib/transcriber/resource/parser.rb +21 -18
  36. data/lib/transcriber/resource/response/embeddable.rb +14 -0
  37. data/lib/transcriber/resource/response/property.rb +11 -0
  38. data/lib/transcriber/resource/response/relation.rb +39 -0
  39. data/lib/transcriber/resource/response.rb +11 -0
  40. data/lib/transcriber/resource/serialization/boolean.rb +32 -9
  41. data/lib/transcriber/resource/serialization/date.rb +7 -7
  42. data/lib/transcriber/resource/serialization/float.rb +9 -5
  43. data/lib/transcriber/resource/serialization/integer.rb +13 -0
  44. data/lib/transcriber/resource/serialization/string.rb +7 -5
  45. data/lib/transcriber/resource.rb +34 -14
  46. data/lib/transcriber/version.rb +1 -1
  47. data/lib/transcriber.rb +38 -2
  48. data/spec/integration/has_many_spec.rb +9 -0
  49. data/spec/integration/property_spec.rb +0 -0
  50. data/spec/spec_helper.rb +22 -1
  51. data/spec/support/examples.rb +21 -0
  52. data/spec/support/out.rb +17 -0
  53. data/spec/unit/configuration_spec.rb +24 -0
  54. data/spec/unit/input_path_spec.rb +68 -0
  55. data/spec/unit/key_spec.rb +48 -0
  56. data/spec/{resource → unit}/parser_spec.rb +16 -21
  57. data/spec/unit/resource/builder/embeddables_spec.rb +27 -0
  58. data/spec/unit/resource/builder/properties_spec.rb +154 -0
  59. data/spec/unit/resource/builder/relations_spec.rb +54 -0
  60. data/spec/unit/resource/builder/shared_example_for_association.rb +20 -0
  61. data/spec/unit/resource/builder/summarize_spec.rb +0 -0
  62. data/spec/unit/resource/key/association_spec.rb +69 -0
  63. data/spec/unit/resource/key/embeddable_spec.rb +7 -0
  64. data/spec/unit/resource/key/property_spec.rb +39 -0
  65. data/spec/unit/resource/key/relation_spec.rb +71 -0
  66. data/spec/unit/resource/parser/embeddable_spec.rb +38 -0
  67. data/spec/unit/resource/parser/property_spec.rb +31 -0
  68. data/spec/unit/resource/response/embeddable_spec.rb +55 -0
  69. data/spec/unit/resource/response/property_spec.rb +22 -0
  70. data/spec/unit/resource/response/relation_spec.rb +105 -0
  71. data/spec/unit/resource/serialization/boolean_spec.rb +25 -0
  72. data/spec/unit/resource/serialization/date_spec.rb +13 -0
  73. data/spec/unit/resource/serialization/float_spec.rb +13 -0
  74. data/spec/unit/resource/serialization/integer_spec.rb +13 -0
  75. data/spec/unit/resource/serialization/string_spec.rb +11 -0
  76. data/spec/unit/resource_spec.rb +46 -0
  77. data/spec/unit/response_spec.rb +44 -0
  78. data/transcriber.gemspec +7 -3
  79. metadata +146 -22
  80. data/lib/transcriber/resource/embeddables/embeddable.rb +0 -31
  81. data/lib/transcriber/resource/embeddables/parser.rb +0 -10
  82. data/lib/transcriber/resource/embeddables/resource.rb +0 -9
  83. data/lib/transcriber/resource/embeddables.rb +0 -18
  84. data/lib/transcriber/resource/properties/parser.rb +0 -9
  85. data/lib/transcriber/resource/properties/property.rb +0 -30
  86. data/lib/transcriber/resource/properties/resource.rb +0 -7
  87. data/lib/transcriber/resource/properties.rb +0 -8
  88. data/lib/transcriber/resource/responses.rb +0 -13
  89. data/lib/transcriber/resource/serialization.rb +0 -10
  90. data/spec/resource/embeddables_spec.rb +0 -228
  91. data/spec/resource/properties_spec.rb +0 -69
  92. data/spec/resource_spec.rb +0 -27
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Response::Property do
4
+ class Customer
5
+ attr_accessor :login
6
+ end
7
+
8
+ subject {Resource::Property.new(:login)}
9
+
10
+ it "returns a pair with property name and value" do
11
+ customer = Customer.new.tap {|c| c.login = "jackiechan2010"}
12
+ subject.to_resource(customer).should == {login: "jackiechan2010"}
13
+ end
14
+
15
+ context "when this key shouldn't be present on resource" do
16
+ it "returns an empty hash" do
17
+ subject.should_receive(:present?).and_return false
18
+ customer = Customer.new.tap {|c| c.login = "jackiechan2010"}
19
+ subject.to_resource(customer).should == {}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Response do
4
+ shared_examples_for "a relation" do
5
+ context "#to_relation" do
6
+ it "returns a pair with property name and value" do
7
+ subject.to_relation(example).should == result
8
+ end
9
+ end
10
+
11
+ context "#to_resource" do
12
+ context "when the key shouldn't be present on resource" do
13
+ it "returns an empty hash" do
14
+ subject.should_receive(:present?).and_return false
15
+ subject.to_resource(example).should == {}
16
+ end
17
+ end
18
+
19
+ context "when the relation instance variable in parent returns nil" do
20
+ it "returns an empty hash" do
21
+ subject.to_resource(example).should == {}
22
+ end
23
+ end
24
+
25
+ context "otherwise" do
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+ context "when has one" do
32
+ before do
33
+ class ExampleChild < Resource
34
+ id
35
+ belongs_to :example
36
+ end
37
+
38
+ class Example < Resource
39
+ id
40
+ has_one :example_child
41
+ end
42
+ end
43
+
44
+ subject {Example.keys[1]}
45
+
46
+ let(:example) {Example.new(id: 100)}
47
+ let(:result) {{rel: :example_child, href: "/examples/100/example_child"}}
48
+
49
+ it_behaves_like "a relation"
50
+ end
51
+
52
+ context "when has many" do
53
+ before do
54
+ class ExampleChild < Resource
55
+ property :id
56
+ belongs_to :example
57
+ end
58
+
59
+ class Example < Resource
60
+ property :id
61
+ has_many :example_children
62
+ end
63
+ end
64
+
65
+ subject {Example.keys[1]}
66
+
67
+ let(:example) {Example.new(id: 200)}
68
+ let(:result) {{rel: :example_children, href: "/examples/200/example_children"}}
69
+
70
+ it_behaves_like "a relation"
71
+ end
72
+
73
+ context "when belongs to one" do
74
+ before do
75
+ class ExampleChild < Resource
76
+ property :id
77
+ belongs_to :example
78
+ end
79
+
80
+ class Example < Resource
81
+ property :id
82
+ has_many :example_children
83
+ end
84
+ end
85
+
86
+ subject {ExampleChild.keys[1]}
87
+
88
+ let(:example) {ExampleChild.new(id: 200)}
89
+ let(:result) {{rel: :example, href: "/examples/200/example_children"}}
90
+
91
+ it_behaves_like "a relation"
92
+ end
93
+
94
+ context "when using forbidden key names" do
95
+ [:resource_id, :resource].each do |forbidden_name|
96
+ it "raises an exception for #{forbidden_name}" do
97
+ expect {
98
+ class Example < Resource
99
+ property forbidden_name
100
+ end
101
+ }.to raise_error
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Serialization::Boolean do
4
+ [true, "true", "TRUE", "1", 1, 1.0, "x", "X", "t", "T"].each do |true_value|
5
+ context "when value is #{true_value}" do
6
+ it "returns true" do
7
+ subject.class.serialize(true_value).should be_true
8
+ end
9
+ end
10
+ end
11
+
12
+ [false, "false", "FALSE", "0", 0, 0.0, "", " ", "f", "F", nil].each do |false_value|
13
+ context "when value is #{false_value}" do
14
+ it "returns false" do
15
+ subject.class.serialize(false_value).should be_false
16
+ end
17
+ end
18
+ end
19
+
20
+ context "when an invalid value is serialized" do
21
+ it "raises an error" do
22
+ expect {subject.class.serialize("neither true or false")}.to raise_error
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Serialization::Date do
4
+ it "converts to date" do
5
+ subject.class.serialize('2011-07-01').should == Date.new(2011, 07, 01)
6
+ end
7
+
8
+ context "when an invalid value is serialized" do
9
+ it "raises an error" do
10
+ expect {subject.class.serialize("not a date")}.to raise_error
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Serialization::Float do
4
+ it "converts to float" do
5
+ subject.class.serialize('1200.49').should == 1200.49
6
+ end
7
+
8
+ context "when an invalid value is serialized" do
9
+ it "raises an error" do
10
+ expect {subject.class.serialize("not a float")}.to raise_error
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Serialization::Integer do
4
+ it "converts to integer" do
5
+ subject.class.serialize('1200').should == 1200
6
+ end
7
+
8
+ context "when an invalid value is serialized" do
9
+ it "raises an error" do
10
+ expect {subject.class.serialize("not an integer")}.to raise_error
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource::Serialization::String do
4
+ it "converts value to string" do
5
+ subject.class.serialize(:something).should == "something"
6
+ end
7
+
8
+ it "returns nil when value is nil" do
9
+ subject.class.serialize(nil).should be_nil
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Resource do
4
+ describe '#resource' do
5
+ before do
6
+ class Example < Resource
7
+ property :login
8
+ property :name
9
+ property :age, type: Float
10
+ end
11
+ end
12
+
13
+ it "returns a hash with properties and its values" do
14
+ example = Example.new(login: 'jackiechan2010', name: 'Jackie Chan', age: 45)
15
+ example.resource.should == {login: 'jackiechan2010', name: 'Jackie Chan', age: 45}
16
+ end
17
+ end
18
+
19
+ context "when using not allowed names" do
20
+ [:resource_id, :resource, :links].each do |unallowed|
21
+ it "warns when method #{unallowed} is redefined" do
22
+ output = out do
23
+ eval <<-RUBY
24
+ class Example < Resource
25
+ def #{unallowed}
26
+ end
27
+ end
28
+ RUBY
29
+ end
30
+ output.should =~ /^warning: redefining '#{unallowed}' may cause serious problems/
31
+ end
32
+
33
+ %w(property embeds_one embeds_many has_one has_many belongs_to).each do |kind|
34
+ it "removes method #{unallowed} created by #{kind}" do
35
+ expect {
36
+ eval <<-RUBY
37
+ class Example < Resource
38
+ #{kind} :#{unallowed}
39
+ end
40
+ RUBY
41
+ }.to raise_error "you can't define a key with name '#{unallowed}'"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transcriber::Resource::Response do
4
+ before do
5
+ class Example < Resource
6
+ id :login
7
+ property :phone
8
+ embeds_one :address, class_name: :example_child
9
+ end
10
+
11
+ class ExampleChild < Resource
12
+ property :street
13
+ property :city
14
+ end
15
+ end
16
+
17
+ let(:input) do
18
+ {
19
+ 'login' => 'jackiechan2010',
20
+ 'phone' => '32232188',
21
+ 'address' => {
22
+ 'street' => 'Aurora St.',
23
+ 'city' => 'Recife'
24
+ }
25
+ }
26
+ end
27
+
28
+ describe "#normalize" do
29
+ context "when one resource is received" do
30
+ it "returns a resource" do
31
+ model = Example.parse(input).first
32
+ Example.normalize(model).with_indifferent_access.should == input.with_indifferent_access
33
+ end
34
+ end
35
+
36
+ context "when a list of resources is received" do
37
+ it "returns some resources in an entries array" do
38
+ model = 3.times.map {Example.parse(input).first}
39
+ result = {entries: 3.times.map {input}}
40
+ Example.normalize(model).with_indifferent_access.should == result.with_indifferent_access
41
+ end
42
+ end
43
+ end
44
+ end
data/transcriber.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "transcriber"
7
7
  s.version = Transcriber::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Victor Rodrigues", "William Yokoi"]
10
- s.email = ["victorcrodrigues@gmail.com", "thekina@gmail.com"]
9
+ s.authors = ["Victor Rodrigues", "William Yokoi", "Guilherme Guimarães Filho"]
10
+ s.email = ["victorcrodrigues@gmail.com", "thekina@gmail.com", "guilherme.filho@locaweb.com.br"]
11
11
  s.homepage = "http://github.com/rodrigues/transcriber"
12
12
  s.summary = %q{}
13
13
  s.description = %q{}
@@ -18,5 +18,9 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency "activesupport", "~> 3.0"
21
- s.add_development_dependency "rspec", "~> 2.6"
21
+ s.add_dependency "i18n", "~> 0.6"
22
+ s.add_development_dependency "rspec", "~> 2.6"
23
+ s.add_development_dependency "guard", "~> 0.5"
24
+ s.add_development_dependency "guard-rspec", "~> 0.4"
25
+ s.add_development_dependency "growl", "~> 1.0"
22
26
  end
metadata CHANGED
@@ -2,16 +2,17 @@
2
2
  name: transcriber
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Victor Rodrigues
9
9
  - William Yokoi
10
+ - "Guilherme Guimar\xC3\xA3es Filho"
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
14
 
14
- date: 2011-07-31 00:00:00 -03:00
15
+ date: 2011-08-11 00:00:00 -03:00
15
16
  default_executable:
16
17
  dependencies:
17
18
  - !ruby/object:Gem::Dependency
@@ -26,20 +27,65 @@ dependencies:
26
27
  type: :runtime
27
28
  version_requirements: *id001
28
29
  - !ruby/object:Gem::Dependency
29
- name: rspec
30
+ name: i18n
30
31
  prerelease: false
31
32
  requirement: &id002 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: "0.6"
38
+ type: :runtime
39
+ version_requirements: *id002
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ prerelease: false
43
+ requirement: &id003 !ruby/object:Gem::Requirement
32
44
  none: false
33
45
  requirements:
34
46
  - - ~>
35
47
  - !ruby/object:Gem::Version
36
48
  version: "2.6"
37
49
  type: :development
38
- version_requirements: *id002
50
+ version_requirements: *id003
51
+ - !ruby/object:Gem::Dependency
52
+ name: guard
53
+ prerelease: false
54
+ requirement: &id004 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "0.5"
60
+ type: :development
61
+ version_requirements: *id004
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ prerelease: false
65
+ requirement: &id005 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: "0.4"
71
+ type: :development
72
+ version_requirements: *id005
73
+ - !ruby/object:Gem::Dependency
74
+ name: growl
75
+ prerelease: false
76
+ requirement: &id006 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: "1.0"
82
+ type: :development
83
+ version_requirements: *id006
39
84
  description: ""
40
85
  email:
41
86
  - victorcrodrigues@gmail.com
42
87
  - thekina@gmail.com
88
+ - guilherme.filho@locaweb.com.br
43
89
  executables: []
44
90
 
45
91
  extensions: []
@@ -49,30 +95,83 @@ extra_rdoc_files: []
49
95
  files:
50
96
  - .gitignore
51
97
  - Gemfile
98
+ - Guardfile
99
+ - README.md
52
100
  - Rakefile
101
+ - examples/all.rb
102
+ - examples/embeds_many/simple.rb
103
+ - examples/embeds_many/with_class_name.rb
104
+ - examples/embeds_many/with_if.rb
105
+ - examples/embeds_many/with_start_key.rb
106
+ - examples/embeds_one/simple.rb
107
+ - examples/embeds_one/with_class_name.rb
108
+ - examples/embeds_one/with_if.rb
109
+ - examples/embeds_one/with_start_key.rb
110
+ - examples/has_many/simple.rb
111
+ - examples/properties/simple.rb
112
+ - examples/properties/with_field.rb
113
+ - examples/properties/with_field_path.rb
114
+ - examples/properties/with_id.rb
115
+ - examples/properties/with_if.rb
116
+ - examples/properties/with_key_converter.rb
53
117
  - lib/transcriber.rb
118
+ - lib/transcriber/configuration.rb
54
119
  - lib/transcriber/resource.rb
55
- - lib/transcriber/resource/embeddables.rb
56
- - lib/transcriber/resource/embeddables/embeddable.rb
57
- - lib/transcriber/resource/embeddables/parser.rb
58
- - lib/transcriber/resource/embeddables/resource.rb
120
+ - lib/transcriber/resource/builder.rb
121
+ - lib/transcriber/resource/builder/embeddables.rb
122
+ - lib/transcriber/resource/builder/keys.rb
123
+ - lib/transcriber/resource/builder/properties.rb
124
+ - lib/transcriber/resource/builder/relations.rb
125
+ - lib/transcriber/resource/builder/summarizations.rb
126
+ - lib/transcriber/resource/input_path.rb
127
+ - lib/transcriber/resource/key.rb
128
+ - lib/transcriber/resource/key/association.rb
129
+ - lib/transcriber/resource/key/embeddable.rb
130
+ - lib/transcriber/resource/key/property.rb
131
+ - lib/transcriber/resource/key/relation.rb
59
132
  - lib/transcriber/resource/parser.rb
60
- - lib/transcriber/resource/properties.rb
61
- - lib/transcriber/resource/properties/parser.rb
62
- - lib/transcriber/resource/properties/property.rb
63
- - lib/transcriber/resource/properties/resource.rb
64
- - lib/transcriber/resource/responses.rb
65
- - lib/transcriber/resource/serialization.rb
133
+ - lib/transcriber/resource/parser/embeddable.rb
134
+ - lib/transcriber/resource/parser/property.rb
135
+ - lib/transcriber/resource/response.rb
136
+ - lib/transcriber/resource/response/embeddable.rb
137
+ - lib/transcriber/resource/response/property.rb
138
+ - lib/transcriber/resource/response/relation.rb
66
139
  - lib/transcriber/resource/serialization/boolean.rb
67
140
  - lib/transcriber/resource/serialization/date.rb
68
141
  - lib/transcriber/resource/serialization/float.rb
142
+ - lib/transcriber/resource/serialization/integer.rb
69
143
  - lib/transcriber/resource/serialization/string.rb
70
144
  - lib/transcriber/version.rb
71
- - spec/resource/embeddables_spec.rb
72
- - spec/resource/parser_spec.rb
73
- - spec/resource/properties_spec.rb
74
- - spec/resource_spec.rb
145
+ - spec/integration/has_many_spec.rb
146
+ - spec/integration/property_spec.rb
75
147
  - spec/spec_helper.rb
148
+ - spec/support/examples.rb
149
+ - spec/support/out.rb
150
+ - spec/unit/configuration_spec.rb
151
+ - spec/unit/input_path_spec.rb
152
+ - spec/unit/key_spec.rb
153
+ - spec/unit/parser_spec.rb
154
+ - spec/unit/resource/builder/embeddables_spec.rb
155
+ - spec/unit/resource/builder/properties_spec.rb
156
+ - spec/unit/resource/builder/relations_spec.rb
157
+ - spec/unit/resource/builder/shared_example_for_association.rb
158
+ - spec/unit/resource/builder/summarize_spec.rb
159
+ - spec/unit/resource/key/association_spec.rb
160
+ - spec/unit/resource/key/embeddable_spec.rb
161
+ - spec/unit/resource/key/property_spec.rb
162
+ - spec/unit/resource/key/relation_spec.rb
163
+ - spec/unit/resource/parser/embeddable_spec.rb
164
+ - spec/unit/resource/parser/property_spec.rb
165
+ - spec/unit/resource/response/embeddable_spec.rb
166
+ - spec/unit/resource/response/property_spec.rb
167
+ - spec/unit/resource/response/relation_spec.rb
168
+ - spec/unit/resource/serialization/boolean_spec.rb
169
+ - spec/unit/resource/serialization/date_spec.rb
170
+ - spec/unit/resource/serialization/float_spec.rb
171
+ - spec/unit/resource/serialization/integer_spec.rb
172
+ - spec/unit/resource/serialization/string_spec.rb
173
+ - spec/unit/resource_spec.rb
174
+ - spec/unit/response_spec.rb
76
175
  - transcriber.gemspec
77
176
  has_rdoc: true
78
177
  homepage: http://github.com/rodrigues/transcriber
@@ -103,8 +202,33 @@ signing_key:
103
202
  specification_version: 3
104
203
  summary: ""
105
204
  test_files:
106
- - spec/resource/embeddables_spec.rb
107
- - spec/resource/parser_spec.rb
108
- - spec/resource/properties_spec.rb
109
- - spec/resource_spec.rb
205
+ - spec/integration/has_many_spec.rb
206
+ - spec/integration/property_spec.rb
110
207
  - spec/spec_helper.rb
208
+ - spec/support/examples.rb
209
+ - spec/support/out.rb
210
+ - spec/unit/configuration_spec.rb
211
+ - spec/unit/input_path_spec.rb
212
+ - spec/unit/key_spec.rb
213
+ - spec/unit/parser_spec.rb
214
+ - spec/unit/resource/builder/embeddables_spec.rb
215
+ - spec/unit/resource/builder/properties_spec.rb
216
+ - spec/unit/resource/builder/relations_spec.rb
217
+ - spec/unit/resource/builder/shared_example_for_association.rb
218
+ - spec/unit/resource/builder/summarize_spec.rb
219
+ - spec/unit/resource/key/association_spec.rb
220
+ - spec/unit/resource/key/embeddable_spec.rb
221
+ - spec/unit/resource/key/property_spec.rb
222
+ - spec/unit/resource/key/relation_spec.rb
223
+ - spec/unit/resource/parser/embeddable_spec.rb
224
+ - spec/unit/resource/parser/property_spec.rb
225
+ - spec/unit/resource/response/embeddable_spec.rb
226
+ - spec/unit/resource/response/property_spec.rb
227
+ - spec/unit/resource/response/relation_spec.rb
228
+ - spec/unit/resource/serialization/boolean_spec.rb
229
+ - spec/unit/resource/serialization/date_spec.rb
230
+ - spec/unit/resource/serialization/float_spec.rb
231
+ - spec/unit/resource/serialization/integer_spec.rb
232
+ - spec/unit/resource/serialization/string_spec.rb
233
+ - spec/unit/resource_spec.rb
234
+ - spec/unit/response_spec.rb
@@ -1,31 +0,0 @@
1
- class Transcriber::Resource
2
- class Embeddable
3
- autoload :Parser, 'transcriber/resource/embeddables/parser'
4
- autoload :Resource, 'transcriber/resource/embeddables/resource'
5
- include Parser
6
- include Resource
7
-
8
- attr_accessor :name
9
- attr_accessor :class_name
10
- attr_accessor :start_key
11
- attr_accessor :many
12
- attr_accessor :options
13
-
14
- def initialize(name, options = {})
15
- @name = name
16
-
17
- @class_name = (options.delete(:class_name) || name).to_s.camelize
18
- @start_key = options.delete(:start_key)
19
- @many = options.delete(:many)
20
- @options = options
21
- end
22
-
23
- def one?
24
- !@many
25
- end
26
-
27
- def many?
28
- @many
29
- end
30
- end
31
- end
@@ -1,10 +0,0 @@
1
- class Transcriber::Resource::Embeddable
2
- module Parser
3
- def parse(item)
4
- options = {}
5
- options.merge!(start_key: start_key) if start_key
6
- value = class_name.constantize.parse(item, options)
7
- one? ? value.first : value
8
- end
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class Transcriber::Resource::Embeddable
2
- module Resource
3
- def to_resource(resource)
4
- resource = resource.__send__(name)
5
- resource = resource.map(&:resource) if resource.kind_of?(Enumerable)
6
- {name => resource}
7
- end
8
- end
9
- end
@@ -1,18 +0,0 @@
1
- class Transcriber::Resource
2
- module Embeddables
3
- def embeds(name, options)
4
- attr_accessor name
5
- keys << Embeddable.new(name, options)
6
- end
7
-
8
- def embeds_one(name, options = {})
9
- options.merge!(many: false)
10
- embeds(name, options)
11
- end
12
-
13
- def embeds_many(name, options = {})
14
- options.merge!(many: true)
15
- embeds(name, options)
16
- end
17
- end
18
- end
@@ -1,9 +0,0 @@
1
- class Transcriber::Resource::Property
2
- module Parser
3
- def parse(item, options = {})
4
- value = serializer.serialize(item[field])
5
- value = values.key(value) if values
6
- value
7
- end
8
- end
9
- end
@@ -1,30 +0,0 @@
1
- class Transcriber::Resource
2
- class Property
3
- autoload :Parser, 'transcriber/resource/properties/parser'
4
- autoload :Resource, 'transcriber/resource/properties/resource'
5
- include Parser
6
- include Resource
7
-
8
- attr_accessor :name
9
- attr_accessor :field
10
- attr_accessor :serializer
11
- attr_accessor :values
12
- attr_accessor :options
13
-
14
- def initialize(name, options = {})
15
- @name = name
16
- @field = prepare_field(options.delete(:field) || name)
17
- @serializer = (options.delete(:type) || Serialization::String)
18
- @values = options.delete(:values)
19
- @options = options
20
- end
21
-
22
- def prepare_field(field)
23
- field.to_s.upcase # @TODO this logic shouldn't be here.
24
- # it's a key conversion strategy
25
- # convert(field).to_s, convert should be
26
- # an identity function if a custom
27
- # strategy was not set.
28
- end
29
- end
30
- end
@@ -1,7 +0,0 @@
1
- class Transcriber::Resource::Property
2
- module Resource
3
- def to_resource(resource)
4
- {name => resource.__send__(name)}
5
- end
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- class Transcriber::Resource
2
- module Properties
3
- def property(name, options = {})
4
- attr_accessor name
5
- keys << Property.new(name, options)
6
- end
7
- end
8
- end