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.
- data/.gitignore +1 -0
- data/Guardfile +7 -0
- data/README.md +39 -0
- data/examples/all.rb +14 -0
- data/examples/embeds_many/simple.rb +14 -0
- data/examples/embeds_many/with_class_name.rb +14 -0
- data/examples/embeds_many/with_if.rb +21 -0
- data/examples/embeds_many/with_start_key.rb +17 -0
- data/examples/embeds_one/simple.rb +14 -0
- data/examples/embeds_one/with_class_name.rb +14 -0
- data/examples/embeds_one/with_if.rb +21 -0
- data/examples/embeds_one/with_start_key.rb +14 -0
- data/examples/has_many/simple.rb +29 -0
- data/examples/properties/simple.rb +10 -0
- data/examples/properties/with_field.rb +10 -0
- data/examples/properties/with_field_path.rb +10 -0
- data/examples/properties/with_id.rb +10 -0
- data/examples/properties/with_if.rb +19 -0
- data/examples/properties/with_key_converter.rb +20 -0
- data/lib/transcriber/configuration.rb +13 -0
- data/lib/transcriber/resource/builder/embeddables.rb +21 -0
- data/lib/transcriber/resource/builder/keys.rb +20 -0
- data/lib/transcriber/resource/builder/properties.rb +29 -0
- data/lib/transcriber/resource/builder/relations.rb +26 -0
- data/lib/transcriber/resource/builder/summarizations.rb +14 -0
- data/lib/transcriber/resource/builder.rb +10 -0
- data/lib/transcriber/resource/input_path.rb +19 -0
- data/lib/transcriber/resource/key/association.rb +29 -0
- data/lib/transcriber/resource/key/embeddable.rb +8 -0
- data/lib/transcriber/resource/key/property.rb +17 -0
- data/lib/transcriber/resource/key/relation.rb +24 -0
- data/lib/transcriber/resource/key.rb +29 -0
- data/lib/transcriber/resource/parser/embeddable.rb +12 -0
- data/lib/transcriber/resource/parser/property.rb +15 -0
- data/lib/transcriber/resource/parser.rb +21 -18
- data/lib/transcriber/resource/response/embeddable.rb +14 -0
- data/lib/transcriber/resource/response/property.rb +11 -0
- data/lib/transcriber/resource/response/relation.rb +39 -0
- data/lib/transcriber/resource/response.rb +11 -0
- data/lib/transcriber/resource/serialization/boolean.rb +32 -9
- data/lib/transcriber/resource/serialization/date.rb +7 -7
- data/lib/transcriber/resource/serialization/float.rb +9 -5
- data/lib/transcriber/resource/serialization/integer.rb +13 -0
- data/lib/transcriber/resource/serialization/string.rb +7 -5
- data/lib/transcriber/resource.rb +34 -14
- data/lib/transcriber/version.rb +1 -1
- data/lib/transcriber.rb +38 -2
- data/spec/integration/has_many_spec.rb +9 -0
- data/spec/integration/property_spec.rb +0 -0
- data/spec/spec_helper.rb +22 -1
- data/spec/support/examples.rb +21 -0
- data/spec/support/out.rb +17 -0
- data/spec/unit/configuration_spec.rb +24 -0
- data/spec/unit/input_path_spec.rb +68 -0
- data/spec/unit/key_spec.rb +48 -0
- data/spec/{resource → unit}/parser_spec.rb +16 -21
- data/spec/unit/resource/builder/embeddables_spec.rb +27 -0
- data/spec/unit/resource/builder/properties_spec.rb +154 -0
- data/spec/unit/resource/builder/relations_spec.rb +54 -0
- data/spec/unit/resource/builder/shared_example_for_association.rb +20 -0
- data/spec/unit/resource/builder/summarize_spec.rb +0 -0
- data/spec/unit/resource/key/association_spec.rb +69 -0
- data/spec/unit/resource/key/embeddable_spec.rb +7 -0
- data/spec/unit/resource/key/property_spec.rb +39 -0
- data/spec/unit/resource/key/relation_spec.rb +71 -0
- data/spec/unit/resource/parser/embeddable_spec.rb +38 -0
- data/spec/unit/resource/parser/property_spec.rb +31 -0
- data/spec/unit/resource/response/embeddable_spec.rb +55 -0
- data/spec/unit/resource/response/property_spec.rb +22 -0
- data/spec/unit/resource/response/relation_spec.rb +105 -0
- data/spec/unit/resource/serialization/boolean_spec.rb +25 -0
- data/spec/unit/resource/serialization/date_spec.rb +13 -0
- data/spec/unit/resource/serialization/float_spec.rb +13 -0
- data/spec/unit/resource/serialization/integer_spec.rb +13 -0
- data/spec/unit/resource/serialization/string_spec.rb +11 -0
- data/spec/unit/resource_spec.rb +46 -0
- data/spec/unit/response_spec.rb +44 -0
- data/transcriber.gemspec +7 -3
- metadata +146 -22
- data/lib/transcriber/resource/embeddables/embeddable.rb +0 -31
- data/lib/transcriber/resource/embeddables/parser.rb +0 -10
- data/lib/transcriber/resource/embeddables/resource.rb +0 -9
- data/lib/transcriber/resource/embeddables.rb +0 -18
- data/lib/transcriber/resource/properties/parser.rb +0 -9
- data/lib/transcriber/resource/properties/property.rb +0 -30
- data/lib/transcriber/resource/properties/resource.rb +0 -7
- data/lib/transcriber/resource/properties.rb +0 -8
- data/lib/transcriber/resource/responses.rb +0 -13
- data/lib/transcriber/resource/serialization.rb +0 -10
- data/spec/resource/embeddables_spec.rb +0 -228
- data/spec/resource/properties_spec.rb +0 -69
- data/spec/resource_spec.rb +0 -27
@@ -1,13 +0,0 @@
|
|
1
|
-
module Transcriber
|
2
|
-
class Resource
|
3
|
-
module Responses
|
4
|
-
def respond_with(model, options = {})
|
5
|
-
response = model.kind_of?(Array) ?
|
6
|
-
model.first.class.resources(model)
|
7
|
-
: model.resource
|
8
|
-
|
9
|
-
[200, {"Content-Type" => "application/json"}, response.to_json]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
module Transcriber
|
2
|
-
class Resource
|
3
|
-
module Serialization
|
4
|
-
autoload :Boolean, 'transcriber/resource/serialization/boolean'
|
5
|
-
autoload :Date, 'transcriber/resource/serialization/date'
|
6
|
-
autoload :Float, 'transcriber/resource/serialization/float'
|
7
|
-
autoload :String, 'transcriber/resource/serialization/string'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Transcriber::Resource::Embeddables do
|
4
|
-
module RelationsExample
|
5
|
-
class Item < Transcriber::Resource
|
6
|
-
end
|
7
|
-
|
8
|
-
class Root < Transcriber::Resource
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
before do
|
13
|
-
RelationsExample::Root.keys.clear
|
14
|
-
RelationsExample::Item.keys.clear
|
15
|
-
end
|
16
|
-
|
17
|
-
describe ".embeds_one" do
|
18
|
-
it "creates a relation" do
|
19
|
-
module RelationsExample
|
20
|
-
class Item < Transcriber::Resource
|
21
|
-
property :id
|
22
|
-
end
|
23
|
-
|
24
|
-
class Root < Transcriber::Resource
|
25
|
-
embeds_one :item
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
RelationsExample::Root.keys.first.name.should == :item
|
30
|
-
end
|
31
|
-
|
32
|
-
it "defines an attr_accessor with relation name" do
|
33
|
-
module RelationsExample
|
34
|
-
class Item < Transcriber::Resource
|
35
|
-
property :id
|
36
|
-
end
|
37
|
-
|
38
|
-
class Root < Transcriber::Resource
|
39
|
-
embeds_one :item
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
RelationsExample::Root.new.tap do |r|
|
44
|
-
r.item = RelationsExample::Item.new(id: 2)
|
45
|
-
r.item.id.should == 2
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "configures class name" do
|
50
|
-
it "uses class_name option if defined" do
|
51
|
-
module RelationsExample
|
52
|
-
class Item < Transcriber::Resource
|
53
|
-
property :id
|
54
|
-
end
|
55
|
-
|
56
|
-
class Root < Transcriber::Resource
|
57
|
-
embeds_one :item, class_name: 'relations_example/item'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
RelationsExample::Root.keys.first.class_name.should == 'RelationsExample::Item'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "uses relation name if class_name option not defined" do
|
65
|
-
module RelationsExample
|
66
|
-
class Item < Transcriber::Resource
|
67
|
-
property :id
|
68
|
-
end
|
69
|
-
|
70
|
-
class Root < Transcriber::Resource
|
71
|
-
embeds_one :item
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
RelationsExample::Root.keys.first.class_name.should == 'Item'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it "configures relation start key if defined" do
|
80
|
-
module RelationsExample
|
81
|
-
class Item < Transcriber::Resource
|
82
|
-
property :id
|
83
|
-
end
|
84
|
-
|
85
|
-
class Root < Transcriber::Resource
|
86
|
-
embeds_one :item, start_key: :item_sap
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
RelationsExample::Root.keys.first.start_key.should == :item_sap
|
91
|
-
end
|
92
|
-
|
93
|
-
it "relation.one? => true and relation.many? => false" do
|
94
|
-
module RelationsExample
|
95
|
-
class Item < Transcriber::Resource
|
96
|
-
property :id
|
97
|
-
end
|
98
|
-
|
99
|
-
class Root < Transcriber::Resource
|
100
|
-
embeds_one :item
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
RelationsExample::Root.keys.first.should be_one
|
105
|
-
RelationsExample::Root.keys.first.should_not be_many
|
106
|
-
end
|
107
|
-
|
108
|
-
it "sets extra options if defined" do
|
109
|
-
module RelationsExample
|
110
|
-
class Item < Transcriber::Resource
|
111
|
-
property :id
|
112
|
-
end
|
113
|
-
|
114
|
-
class Root < Transcriber::Resource
|
115
|
-
embeds_one :item, restricted: 'admin'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
RelationsExample::Root.keys.first.options[:restricted].should == 'admin'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe ".embeds_many" do
|
124
|
-
it "creates a relation" do
|
125
|
-
module RelationsExample
|
126
|
-
class Item < Transcriber::Resource
|
127
|
-
property :id
|
128
|
-
end
|
129
|
-
|
130
|
-
class Root < Transcriber::Resource
|
131
|
-
embeds_many :item
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
RelationsExample::Root.keys.first.name.should == :item
|
136
|
-
end
|
137
|
-
|
138
|
-
it "defines an attr_accessor with relation name" do
|
139
|
-
module RelationsExample
|
140
|
-
class Item < Transcriber::Resource
|
141
|
-
property :id
|
142
|
-
end
|
143
|
-
|
144
|
-
class Root < Transcriber::Resource
|
145
|
-
embeds_many :item
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
RelationsExample::Root.new.tap do |r|
|
150
|
-
r.item = RelationsExample::Item.new(id: 2)
|
151
|
-
r.item.id.should == 2
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "configures class name" do
|
156
|
-
it "uses class_name option if defined" do
|
157
|
-
module RelationsExample
|
158
|
-
class Item < Transcriber::Resource
|
159
|
-
property :id
|
160
|
-
end
|
161
|
-
|
162
|
-
class Root < Transcriber::Resource
|
163
|
-
embeds_many :item, class_name: 'relations_example/item'
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
RelationsExample::Root.keys.first.class_name.should == 'RelationsExample::Item'
|
168
|
-
end
|
169
|
-
|
170
|
-
it "uses relation name if class_name option not defined" do
|
171
|
-
module RelationsExample
|
172
|
-
class Item < Transcriber::Resource
|
173
|
-
property :id
|
174
|
-
end
|
175
|
-
|
176
|
-
class Root < Transcriber::Resource
|
177
|
-
embeds_many :item
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
RelationsExample::Root.keys.first.class_name.should == 'Item'
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
it "configures relation start key if defined" do
|
186
|
-
module RelationsExample
|
187
|
-
class Item < Transcriber::Resource
|
188
|
-
property :id
|
189
|
-
end
|
190
|
-
|
191
|
-
class Root < Transcriber::Resource
|
192
|
-
embeds_many :item, start_key: :item_sap
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
RelationsExample::Root.keys.first.start_key.should == :item_sap
|
197
|
-
end
|
198
|
-
|
199
|
-
it "relation.one? => false and relation.many? => true" do
|
200
|
-
module RelationsExample
|
201
|
-
class Item < Transcriber::Resource
|
202
|
-
property :id
|
203
|
-
end
|
204
|
-
|
205
|
-
class Root < Transcriber::Resource
|
206
|
-
embeds_many :item
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
RelationsExample::Root.keys.first.should_not be_one
|
211
|
-
RelationsExample::Root.keys.first.should be_many
|
212
|
-
end
|
213
|
-
|
214
|
-
it "sets extra options if defined" do
|
215
|
-
module RelationsExample
|
216
|
-
class Item < Transcriber::Resource
|
217
|
-
property :id
|
218
|
-
end
|
219
|
-
|
220
|
-
class Root < Transcriber::Resource
|
221
|
-
embeds_many :item, restricted: 'admin'
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
RelationsExample::Root.keys.first.options[:restricted].should == 'admin'
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Transcriber::Resource::Properties do
|
4
|
-
class Example < Transcriber::Resource
|
5
|
-
end
|
6
|
-
|
7
|
-
before { Example.keys.clear }
|
8
|
-
|
9
|
-
describe ".property" do
|
10
|
-
it "creates a property" do
|
11
|
-
class Example
|
12
|
-
property :login
|
13
|
-
end
|
14
|
-
|
15
|
-
Example.keys.first.name.should == :login
|
16
|
-
end
|
17
|
-
|
18
|
-
it "defines an attr_accessor with property name" do
|
19
|
-
class Example
|
20
|
-
property :id
|
21
|
-
end
|
22
|
-
|
23
|
-
Example.new.tap do |example|
|
24
|
-
example.id = 2020
|
25
|
-
example.id.should == 2020
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "configures a default serializer" do
|
30
|
-
class Example
|
31
|
-
property :login
|
32
|
-
end
|
33
|
-
|
34
|
-
Example.keys.first.serializer.should == Transcriber::Resource::Serialization::String
|
35
|
-
end
|
36
|
-
|
37
|
-
it "configures a default field" do
|
38
|
-
class Example
|
39
|
-
property :login
|
40
|
-
end
|
41
|
-
|
42
|
-
Example.keys.first.field.should == "LOGIN"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "sets property type if defined" do
|
46
|
-
class Example
|
47
|
-
property :login, type: Transcriber::Resource::Serialization::Date
|
48
|
-
end
|
49
|
-
|
50
|
-
Example.keys.first.serializer.should == Transcriber::Resource::Serialization::Date
|
51
|
-
end
|
52
|
-
|
53
|
-
it "sets property values if defined" do
|
54
|
-
class Example
|
55
|
-
property :login, values: {a: '1', b: '2'}
|
56
|
-
end
|
57
|
-
|
58
|
-
Example.keys.first.values.should == {a: '1', b: '2'}
|
59
|
-
end
|
60
|
-
|
61
|
-
it "sets extra options if defined" do
|
62
|
-
class Example
|
63
|
-
property :login, restricted: 'admin'
|
64
|
-
end
|
65
|
-
|
66
|
-
Example.keys.first.options[:restricted].should == 'admin'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/resource_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Transcriber::Resource do
|
4
|
-
class ExampleResources < Transcriber::Resource
|
5
|
-
property :login
|
6
|
-
property :name
|
7
|
-
property :age, type: Float
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#resource' do
|
11
|
-
it "returns a hash with properties and its values" do
|
12
|
-
example = ExampleResources.new(login: 'jackiechan2010', name: 'Jackie Chan', age: 45)
|
13
|
-
example.resource.should == {login: 'jackiechan2010', name: 'Jackie Chan', age: 45}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '.resources' do
|
18
|
-
it "returns a hash with entries" do
|
19
|
-
entries = [ExampleResources.new(login: 'jackiechan2010', name: 'Jackie Chan', age: 45),
|
20
|
-
ExampleResources.new(login: 'brucelee', name: 'Bruce Lee', age: 10)]
|
21
|
-
|
22
|
-
resources = ExampleResources.resources(entries)
|
23
|
-
resources.should == {entries: [{login: 'jackiechan2010', name: 'Jackie Chan', age: 45},
|
24
|
-
{login: 'brucelee', name: 'Bruce Lee', age: 10}]}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|