beefcake 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/protoc-gen-beefcake +74 -36
- metadata +4 -4
data/bin/protoc-gen-beefcake
CHANGED
@@ -133,7 +133,7 @@ end
|
|
133
133
|
|
134
134
|
|
135
135
|
module Beefcake
|
136
|
-
class Generator
|
136
|
+
class Generator
|
137
137
|
|
138
138
|
L = CodeGeneratorRequest::FieldDescriptorProto::Label
|
139
139
|
T = CodeGeneratorRequest::FieldDescriptorProto::Type
|
@@ -154,45 +154,67 @@ module Beefcake
|
|
154
154
|
CodeGeneratorResponse.new(:file => file)
|
155
155
|
end
|
156
156
|
|
157
|
+
attr_reader :c
|
158
|
+
|
159
|
+
def initialize(c)
|
160
|
+
@c = c
|
161
|
+
@n = 0
|
162
|
+
end
|
163
|
+
|
157
164
|
def file!(file)
|
158
|
-
|
165
|
+
puts "## Generated from #{file.name} for #{file.package}"
|
159
166
|
|
160
167
|
file.message_type.each do |mt|
|
161
168
|
message!(mt)
|
162
169
|
end
|
163
170
|
end
|
164
171
|
|
165
|
-
def
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
mt.enum_type.each do |et|
|
172
|
-
enum!(et)
|
173
|
-
end
|
172
|
+
def indent(&blk)
|
173
|
+
@n += 1
|
174
|
+
blk.call
|
175
|
+
@n -= 1
|
176
|
+
end
|
174
177
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
end
|
179
|
-
c.puts
|
178
|
+
def indent!(n)
|
179
|
+
@n = n
|
180
|
+
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
def message!(pkg, mt)
|
183
|
+
puts
|
184
|
+
puts "class #{mt.name}"
|
185
|
+
|
186
|
+
indent do
|
187
|
+
puts "include Beefcake::Message"
|
188
|
+
puts
|
189
|
+
|
190
|
+
mt.enum_type.each do |et|
|
191
|
+
enum!(et)
|
192
|
+
end
|
193
|
+
|
194
|
+
## Generate Types
|
195
|
+
(mt.nested_type || []).each do |nt|
|
196
|
+
message!(nt)
|
197
|
+
end
|
198
|
+
puts
|
199
|
+
|
200
|
+
## Generate fields
|
201
|
+
(mt.field || []).each do |f|
|
202
|
+
field!(pkg, f)
|
203
|
+
end
|
204
|
+
puts
|
184
205
|
end
|
185
|
-
c.puts
|
186
206
|
|
187
|
-
|
207
|
+
puts "end"
|
188
208
|
end
|
189
209
|
|
190
210
|
def enum!(et)
|
191
|
-
|
192
|
-
|
193
|
-
|
211
|
+
puts "module #{et.name}"
|
212
|
+
indent do
|
213
|
+
et.value.each do |v|
|
214
|
+
puts "%s = %d" % [v.name, v.number]
|
215
|
+
end
|
194
216
|
end
|
195
|
-
|
217
|
+
puts "end"
|
196
218
|
end
|
197
219
|
|
198
220
|
def field!(pkg, f)
|
@@ -216,13 +238,13 @@ module Beefcake
|
|
216
238
|
end
|
217
239
|
|
218
240
|
# Finally, generate the declaration
|
219
|
-
|
241
|
+
out = "%s %s, %s, %d" % [label, name, type, f.number]
|
220
242
|
|
221
243
|
if f.default_value
|
222
|
-
|
244
|
+
out += ", :default => #{f.default_value}"
|
223
245
|
end
|
224
246
|
|
225
|
-
|
247
|
+
puts out
|
226
248
|
end
|
227
249
|
|
228
250
|
# Determines the name for a
|
@@ -231,18 +253,34 @@ module Beefcake
|
|
231
253
|
end
|
232
254
|
|
233
255
|
def compile(ns, file)
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
256
|
+
puts "## Generated from #{file.name} for #{file.package}"
|
257
|
+
puts "require \"beefcake\""
|
258
|
+
puts
|
259
|
+
|
260
|
+
ns!(*ns) do
|
261
|
+
file.message_type.each do |mt|
|
262
|
+
message!(file.package, mt)
|
263
|
+
end
|
238
264
|
end
|
265
|
+
end
|
239
266
|
|
240
|
-
|
241
|
-
|
267
|
+
def ns!(n, *tail, &blk)
|
268
|
+
puts "module #{n}"
|
269
|
+
indent do
|
270
|
+
if tail.empty?
|
271
|
+
blk.call
|
272
|
+
else
|
273
|
+
ns!(*tail, &blk)
|
274
|
+
end
|
242
275
|
end
|
276
|
+
puts "end"
|
277
|
+
end
|
243
278
|
|
244
|
-
|
245
|
-
|
279
|
+
def puts(msg=nil)
|
280
|
+
if msg
|
281
|
+
c.puts((" " * @n) + msg)
|
282
|
+
else
|
283
|
+
c.puts
|
246
284
|
end
|
247
285
|
end
|
248
286
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beefcake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Blake Mizerany
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-23 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|