transcriber 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/lib/transcriber/resource/embeddables/embeddable.rb +31 -0
- data/lib/transcriber/resource/embeddables/parser.rb +10 -0
- data/lib/transcriber/resource/embeddables/resource.rb +9 -0
- data/lib/transcriber/resource/embeddables.rb +18 -0
- data/lib/transcriber/resource/parser.rb +26 -0
- data/lib/transcriber/resource/properties/parser.rb +9 -0
- data/lib/transcriber/resource/properties/property.rb +30 -0
- data/lib/transcriber/resource/properties/resource.rb +7 -0
- data/lib/transcriber/resource/properties.rb +8 -0
- data/lib/transcriber/resource/responses.rb +13 -0
- data/lib/transcriber/resource/serialization/boolean.rb +14 -0
- data/lib/transcriber/resource/serialization/date.rb +13 -0
- data/lib/transcriber/resource/serialization/float.rb +9 -0
- data/lib/transcriber/resource/serialization/string.rb +9 -0
- data/lib/transcriber/resource/serialization.rb +10 -0
- data/lib/transcriber/resource.rb +32 -0
- data/lib/transcriber/version.rb +3 -0
- data/lib/transcriber.rb +6 -0
- data/spec/resource/embeddables_spec.rb +228 -0
- data/spec/resource/parser_spec.rb +90 -0
- data/spec/resource/properties_spec.rb +69 -0
- data/spec/resource_spec.rb +27 -0
- data/spec/spec_helper.rb +1 -0
- data/transcriber.gemspec +22 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Transcriber::Resource
|
2
|
+
module Parser
|
3
|
+
def parse(input, options = {})
|
4
|
+
entries(input, options).collect {|item| parse_one(item)}
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def entries(input, options)
|
10
|
+
start_key = options[:start_key]
|
11
|
+
entries = input
|
12
|
+
if entries.kind_of?(Hash)
|
13
|
+
entries = entries[start_key.to_s.upcase] if start_key
|
14
|
+
entries = [entries]
|
15
|
+
end
|
16
|
+
entries
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_one(item)
|
20
|
+
params = keys.inject({}) do |buffer, key|
|
21
|
+
buffer.merge key.name => key.parse(item)
|
22
|
+
end
|
23
|
+
self.new(params)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Transcriber::Resource
|
2
|
+
module Serialization
|
3
|
+
class Boolean
|
4
|
+
MAPPINGS = {true => [true, "true", "TRUE", "1", 1, 1.0, "x", "X", "t", "T"],
|
5
|
+
false => [false, "false", "FALSE", "0", 0, 0.0, "", " ", "f", "F", nil]}
|
6
|
+
|
7
|
+
def self.serialize(value)
|
8
|
+
return true if MAPPINGS[true].include?(value)
|
9
|
+
return false if MAPPINGS[false].include?(value)
|
10
|
+
raise "value not serializable: #{{value: value, mappings: MAPPINGS}}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
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
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Transcriber
|
2
|
+
class Resource
|
3
|
+
autoload :Serialization, 'transcriber/resource/serialization'
|
4
|
+
autoload :Properties, 'transcriber/resource/properties'
|
5
|
+
autoload :Property, 'transcriber/resource/properties/property'
|
6
|
+
autoload :Embeddables, 'transcriber/resource/embeddables'
|
7
|
+
autoload :Embeddable, 'transcriber/resource/embeddables/embeddable'
|
8
|
+
autoload :Parser, 'transcriber/resource/parser'
|
9
|
+
autoload :Responses, 'transcriber/resource/responses'
|
10
|
+
|
11
|
+
extend Properties
|
12
|
+
extend Embeddables
|
13
|
+
extend Parser
|
14
|
+
include Serialization
|
15
|
+
|
16
|
+
def initialize(attrs = {})
|
17
|
+
attrs.map {|name, value| send("#{name}=", value)}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.keys
|
21
|
+
@keys ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.resources(entries)
|
25
|
+
{entries: entries.map(&:resource)}
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource
|
29
|
+
self.class.keys.inject({}) {|buffer, key| buffer.merge key.to_resource(self)}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/transcriber.rb
ADDED
@@ -0,0 +1,228 @@
|
|
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
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transcriber::Resource::Parser do
|
4
|
+
class Example < Transcriber::Resource
|
5
|
+
end
|
6
|
+
|
7
|
+
before { Example.keys.clear }
|
8
|
+
|
9
|
+
describe '.parse' do
|
10
|
+
it 'parses simple properties' do
|
11
|
+
class Example < Transcriber::Resource
|
12
|
+
property :login
|
13
|
+
end
|
14
|
+
|
15
|
+
models = Example.parse({'LOGIN' => 'jackiechan2010'})
|
16
|
+
models.should be_an(Array)
|
17
|
+
models.first.login.should == 'jackiechan2010'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'uses different field name if defined' do
|
21
|
+
class Example < Transcriber::Resource
|
22
|
+
property :login, field: :customer_login
|
23
|
+
end
|
24
|
+
|
25
|
+
models = Example.parse({'CUSTOMER_LOGIN' => 'jackiechan2010'})
|
26
|
+
models.should be_an(Array)
|
27
|
+
models.first.login.should == 'jackiechan2010'
|
28
|
+
end
|
29
|
+
|
30
|
+
context "uses type defined" do
|
31
|
+
context 'boolean' do
|
32
|
+
before do
|
33
|
+
class Example < Transcriber::Resource
|
34
|
+
property :can_merge, type: Boolean
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns true when value is 'X'" do
|
39
|
+
models = Example.parse({'CAN_MERGE' => 'X'})
|
40
|
+
models.first.can_merge.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false when value isn't 'X'" do
|
44
|
+
models = Example.parse({'CAN_MERGE' => ''})
|
45
|
+
models.first.can_merge.should be_false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "date" do
|
50
|
+
it "parse" do
|
51
|
+
class Example < Transcriber::Resource
|
52
|
+
property :issue_date, type: Date
|
53
|
+
end
|
54
|
+
|
55
|
+
models = Example.parse({'ISSUE_DATE' => '2011-01-01'})
|
56
|
+
models.first.issue_date.should == Date.parse('2011-01-01')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "float" do
|
61
|
+
it "parse" do
|
62
|
+
class Example < Transcriber::Resource
|
63
|
+
property :amount, type: Float
|
64
|
+
end
|
65
|
+
|
66
|
+
models = Example.parse({'AMOUNT' => '1234.5'})
|
67
|
+
models.first.amount.should == 1234.5
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "maps values if defined" do
|
73
|
+
before do
|
74
|
+
class Example < Transcriber::Resource
|
75
|
+
property :status, values: {paid: '01', unpaid: '02'}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns key when value was mapped" do
|
80
|
+
models = Example.parse({'STATUS' => '02'})
|
81
|
+
models.first.status.should == :unpaid
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns nil when value wasn't mapped" do
|
85
|
+
models = Example.parse({'STATUS' => '03'})
|
86
|
+
models.first.status.should be_nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'transcriber'
|
data/transcriber.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "transcriber/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "transcriber"
|
7
|
+
s.version = Transcriber::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Victor Rodrigues", "William Yokoi"]
|
10
|
+
s.email = ["victorcrodrigues@gmail.com", "thekina@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/rodrigues/transcriber"
|
12
|
+
s.summary = %q{}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "activesupport", "~> 3.0"
|
21
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transcriber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Rodrigues
|
9
|
+
- William Yokoi
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-07-31 00:00:00 -03:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: activesupport
|
19
|
+
prerelease: false
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: "3.0"
|
26
|
+
type: :runtime
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
prerelease: false
|
31
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: "2.6"
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id002
|
39
|
+
description: ""
|
40
|
+
email:
|
41
|
+
- victorcrodrigues@gmail.com
|
42
|
+
- thekina@gmail.com
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
extra_rdoc_files: []
|
48
|
+
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- Rakefile
|
53
|
+
- lib/transcriber.rb
|
54
|
+
- 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
|
59
|
+
- 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
|
66
|
+
- lib/transcriber/resource/serialization/boolean.rb
|
67
|
+
- lib/transcriber/resource/serialization/date.rb
|
68
|
+
- lib/transcriber/resource/serialization/float.rb
|
69
|
+
- lib/transcriber/resource/serialization/string.rb
|
70
|
+
- 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
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- transcriber.gemspec
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/rodrigues/transcriber
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.6.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: ""
|
105
|
+
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
|
110
|
+
- spec/spec_helper.rb
|