ruby-protocol-buffers 1.1.0 → 1.2.0
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/VERSION +1 -1
- data/bin/ruby-protoc +4 -2
- data/lib/protocol_buffers/compiler.rb +6 -1
- data/lib/protocol_buffers/compiler/file_descriptor_to_ruby.rb +22 -15
- data/spec/proto_files/dotted_package.proto +9 -0
- data/spec/proto_files/under_score_package.proto +11 -0
- data/spec/runtime_spec.rb +11 -0
- metadata +100 -62
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.2.0
|
data/bin/ruby-protoc
CHANGED
|
@@ -45,9 +45,11 @@ end
|
|
|
45
45
|
|
|
46
46
|
descriptor_set.file.each do |file_descriptor|
|
|
47
47
|
|
|
48
|
+
fullpath = filenames[filenames.index{|path| path.include? file_descriptor.name}]
|
|
49
|
+
|
|
48
50
|
if ruby_out
|
|
49
|
-
path = File.join(ruby_out,
|
|
50
|
-
|
|
51
|
+
path = File.join(ruby_out,File.dirname(fullpath),File.basename(file_descriptor.name, ".proto") + ".pb.rb")
|
|
52
|
+
FileUtils.mkpath(File.dirname(path)) unless File.directory?(File.dirname(path))
|
|
51
53
|
File.open(path, "wb") do |file|
|
|
52
54
|
dumper = FileDescriptorToRuby.new(file_descriptor)
|
|
53
55
|
dumper.write(file)
|
|
@@ -9,7 +9,6 @@ module ProtocolBuffers
|
|
|
9
9
|
raise(ArgumentError, "Need at least one input file") if input_files.empty?
|
|
10
10
|
other_opts = ""
|
|
11
11
|
(opts[:include_dirs] || []).each { |d| other_opts += " -I#{d}" }
|
|
12
|
-
input_files.each { |f| other_opts += " -I#{File.dirname(f)}" }
|
|
13
12
|
|
|
14
13
|
cmd = "protoc #{other_opts} -o#{output_filename} #{input_files.join(' ')}"
|
|
15
14
|
rc = system(cmd)
|
|
@@ -21,8 +20,14 @@ module ProtocolBuffers
|
|
|
21
20
|
require 'tempfile'
|
|
22
21
|
require 'protocol_buffers/compiler/file_descriptor_to_ruby'
|
|
23
22
|
|
|
23
|
+
input_files = Array(input_files) unless input_files.is_a?(Array)
|
|
24
|
+
|
|
24
25
|
tempfile = Tempfile.new("protocol_buffers_spec")
|
|
25
26
|
tempfile.binmode
|
|
27
|
+
|
|
28
|
+
include_dirs = (opts[:include_dirs] ||= [])
|
|
29
|
+
include_dirs.concat(input_files.map { |i| File.dirname(i) }.uniq)
|
|
30
|
+
|
|
26
31
|
compile(tempfile.path, input_files, opts)
|
|
27
32
|
descriptor_set = FileDescriptorSet.parse(tempfile)
|
|
28
33
|
tempfile.close(true)
|
|
@@ -8,7 +8,7 @@ class FileDescriptorToRuby < Struct.new(:descriptor)
|
|
|
8
8
|
|
|
9
9
|
def initialize(descriptor)
|
|
10
10
|
super
|
|
11
|
-
@
|
|
11
|
+
@package_modules = descriptor.package_ ? descriptor.package_.split('.') : []
|
|
12
12
|
@ns = []
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -22,21 +22,21 @@ class FileDescriptorToRuby < Struct.new(:descriptor)
|
|
|
22
22
|
require 'protocol_buffers'
|
|
23
23
|
|
|
24
24
|
HEADER
|
|
25
|
+
|
|
25
26
|
descriptor.dependency.each do |dep|
|
|
26
27
|
path = File.basename(dep, ".proto") + ".pb"
|
|
27
28
|
@io.write("begin; require '#{path}'; rescue LoadError; end\n")
|
|
28
29
|
end
|
|
29
30
|
@io.write("\n") unless descriptor.dependency.empty?
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
in_namespace("module", @package) do
|
|
32
|
+
in_namespace("module", @package_modules) do
|
|
33
33
|
declare(descriptor.message_type, descriptor.enum_type)
|
|
34
34
|
|
|
35
35
|
descriptor.message_type.each do |message|
|
|
36
36
|
dump_message(message)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
protected
|
|
@@ -46,7 +46,7 @@ HEADER
|
|
|
46
46
|
|
|
47
47
|
line %{# forward declarations}
|
|
48
48
|
messages.each do |message|
|
|
49
|
-
line %{class #{name([@
|
|
49
|
+
line %{class #{name([@package_modules, message.name].flatten)} < ::ProtocolBuffers::Message; end}
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
if enums.empty?
|
|
@@ -67,14 +67,17 @@ HEADER
|
|
|
67
67
|
end
|
|
68
68
|
@io.write("\n")
|
|
69
69
|
end
|
|
70
|
-
|
|
71
|
-
def in_namespace(type,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
|
|
71
|
+
def in_namespace(type, namespace, rest = "")
|
|
72
|
+
|
|
73
|
+
namespace_array = [namespace].flatten
|
|
74
|
+
|
|
75
|
+
namespace_array.each do |n|
|
|
76
|
+
line "#{type} #{camelize(n)}#{rest}"
|
|
77
|
+
@ns.push n
|
|
78
|
+
end
|
|
79
|
+
yield
|
|
80
|
+
namespace_array.each do |n|
|
|
78
81
|
@ns.pop
|
|
79
82
|
line "end"
|
|
80
83
|
end
|
|
@@ -83,7 +86,7 @@ HEADER
|
|
|
83
86
|
def name(parts)
|
|
84
87
|
ns = @ns.dup
|
|
85
88
|
(parts.shift; ns.shift) while !parts.empty? && parts.first == ns.first
|
|
86
|
-
parts.map { |p|
|
|
89
|
+
parts.map { |p| camelize(p) }.join("::")
|
|
87
90
|
end
|
|
88
91
|
|
|
89
92
|
LABEL_MAPPING = {
|
|
@@ -143,7 +146,7 @@ HEADER
|
|
|
143
146
|
end
|
|
144
147
|
|
|
145
148
|
def field_typename(field)
|
|
146
|
-
TYPE_MAPPING[field.type] || field.type_name.split(".").map { |t|
|
|
149
|
+
TYPE_MAPPING[field.type] || field.type_name.split(".").map { |t| camelize(t) }.join("::")
|
|
147
150
|
end
|
|
148
151
|
|
|
149
152
|
# TODO: this probably doesn't work for all default values, expand
|
|
@@ -164,5 +167,9 @@ HEADER
|
|
|
164
167
|
def capfirst(s)
|
|
165
168
|
"#{s[0,1].capitalize}#{s[1..-1]}" if s
|
|
166
169
|
end
|
|
170
|
+
|
|
171
|
+
def camelize(lower_case_and_underscored_word)
|
|
172
|
+
lower_case_and_underscored_word.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }
|
|
173
|
+
end
|
|
167
174
|
|
|
168
175
|
end
|
data/spec/runtime_spec.rb
CHANGED
|
@@ -486,5 +486,16 @@ describe ProtocolBuffers, "runtime" do
|
|
|
486
486
|
res3 = TehUnknown3::MyResult.parse(serialized2)
|
|
487
487
|
res3.field_1.should == 2
|
|
488
488
|
end
|
|
489
|
+
|
|
490
|
+
it "can compile and instantiate a message in a package with under_scores" do
|
|
491
|
+
Object.send(:remove_const, :UnderScore) if defined?(UnderScore)
|
|
492
|
+
|
|
493
|
+
ProtocolBuffers::Compiler.compile_and_load(
|
|
494
|
+
File.join(File.dirname(__FILE__), "proto_files", "under_score_package.proto"))
|
|
495
|
+
|
|
496
|
+
proc do
|
|
497
|
+
under_test = UnderScore::UnderTest.new
|
|
498
|
+
end.should_not raise_error()
|
|
499
|
+
end
|
|
489
500
|
|
|
490
501
|
end
|
metadata
CHANGED
|
@@ -1,80 +1,104 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-protocol-buffers
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 1
|
|
8
|
+
- 2
|
|
9
|
+
- 0
|
|
10
|
+
version: 1.2.0
|
|
6
11
|
platform: ruby
|
|
7
|
-
authors:
|
|
12
|
+
authors:
|
|
8
13
|
- Brian Palmer
|
|
9
14
|
autorequire:
|
|
10
15
|
bindir: bin
|
|
11
16
|
cert_chain: []
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
date: 2011-10-01 00:00:00 -06:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
15
22
|
name: rspec
|
|
16
|
-
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
17
25
|
none: false
|
|
18
|
-
requirements:
|
|
26
|
+
requirements:
|
|
19
27
|
- - ~>
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 9
|
|
30
|
+
segments:
|
|
31
|
+
- 2
|
|
32
|
+
- 5
|
|
33
|
+
version: "2.5"
|
|
22
34
|
type: :development
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- !ruby/object:Gem::Dependency
|
|
35
|
+
version_requirements: *id001
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
26
37
|
name: autotest-standalone
|
|
27
|
-
|
|
38
|
+
prerelease: false
|
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
28
40
|
none: false
|
|
29
|
-
requirements:
|
|
30
|
-
- -
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
hash: 3
|
|
45
|
+
segments:
|
|
46
|
+
- 0
|
|
47
|
+
version: "0"
|
|
33
48
|
type: :development
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- !ruby/object:Gem::Dependency
|
|
49
|
+
version_requirements: *id002
|
|
50
|
+
- !ruby/object:Gem::Dependency
|
|
37
51
|
name: autotest-growl
|
|
38
|
-
|
|
52
|
+
prerelease: false
|
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
39
54
|
none: false
|
|
40
|
-
requirements:
|
|
41
|
-
- -
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
hash: 3
|
|
59
|
+
segments:
|
|
60
|
+
- 0
|
|
61
|
+
version: "0"
|
|
44
62
|
type: :development
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
- !ruby/object:Gem::Dependency
|
|
63
|
+
version_requirements: *id003
|
|
64
|
+
- !ruby/object:Gem::Dependency
|
|
48
65
|
name: rcov
|
|
49
|
-
|
|
66
|
+
prerelease: false
|
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
50
68
|
none: false
|
|
51
|
-
requirements:
|
|
52
|
-
- -
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
hash: 3
|
|
73
|
+
segments:
|
|
74
|
+
- 0
|
|
75
|
+
version: "0"
|
|
55
76
|
type: :development
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- !ruby/object:Gem::Dependency
|
|
77
|
+
version_requirements: *id004
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
59
79
|
name: yard
|
|
60
|
-
|
|
80
|
+
prerelease: false
|
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
61
82
|
none: false
|
|
62
|
-
requirements:
|
|
63
|
-
- -
|
|
64
|
-
- !ruby/object:Gem::Version
|
|
65
|
-
|
|
83
|
+
requirements:
|
|
84
|
+
- - ">="
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
hash: 3
|
|
87
|
+
segments:
|
|
88
|
+
- 0
|
|
89
|
+
version: "0"
|
|
66
90
|
type: :development
|
|
67
|
-
|
|
68
|
-
version_requirements: *70109784524700
|
|
91
|
+
version_requirements: *id005
|
|
69
92
|
description:
|
|
70
|
-
email:
|
|
93
|
+
email:
|
|
71
94
|
- brian@codekitchen.net
|
|
72
|
-
executables:
|
|
95
|
+
executables:
|
|
73
96
|
- ruby-protoc
|
|
74
97
|
extensions: []
|
|
75
|
-
|
|
98
|
+
|
|
99
|
+
extra_rdoc_files:
|
|
76
100
|
- Changelog.md
|
|
77
|
-
files:
|
|
101
|
+
files:
|
|
78
102
|
- .document
|
|
79
103
|
- .gitignore
|
|
80
104
|
- Changelog.md
|
|
@@ -112,45 +136,59 @@ files:
|
|
|
112
136
|
- spec/compiler_spec.rb
|
|
113
137
|
- spec/fields_spec.rb
|
|
114
138
|
- spec/proto_files/depends.proto
|
|
139
|
+
- spec/proto_files/dotted_package.proto
|
|
115
140
|
- spec/proto_files/featureful.proto
|
|
116
141
|
- spec/proto_files/no_package.proto
|
|
117
142
|
- spec/proto_files/simple.proto
|
|
118
143
|
- spec/proto_files/top_level_enum.proto
|
|
144
|
+
- spec/proto_files/under_score_package.proto
|
|
119
145
|
- spec/runtime_spec.rb
|
|
120
146
|
- spec/spec.opts
|
|
121
147
|
- spec/spec_helper.rb
|
|
148
|
+
has_rdoc: true
|
|
122
149
|
homepage: https://github.com/mozy/ruby-protocol-buffers
|
|
123
150
|
licenses: []
|
|
151
|
+
|
|
124
152
|
post_install_message:
|
|
125
153
|
rdoc_options: []
|
|
126
|
-
|
|
154
|
+
|
|
155
|
+
require_paths:
|
|
127
156
|
- lib
|
|
128
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
158
|
none: false
|
|
130
|
-
requirements:
|
|
131
|
-
- -
|
|
132
|
-
- !ruby/object:Gem::Version
|
|
133
|
-
|
|
134
|
-
|
|
159
|
+
requirements:
|
|
160
|
+
- - ">="
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
hash: 3
|
|
163
|
+
segments:
|
|
164
|
+
- 0
|
|
165
|
+
version: "0"
|
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
167
|
none: false
|
|
136
|
-
requirements:
|
|
137
|
-
- -
|
|
138
|
-
- !ruby/object:Gem::Version
|
|
139
|
-
|
|
168
|
+
requirements:
|
|
169
|
+
- - ">="
|
|
170
|
+
- !ruby/object:Gem::Version
|
|
171
|
+
hash: 3
|
|
172
|
+
segments:
|
|
173
|
+
- 0
|
|
174
|
+
version: "0"
|
|
140
175
|
requirements: []
|
|
176
|
+
|
|
141
177
|
rubyforge_project:
|
|
142
|
-
rubygems_version: 1.
|
|
178
|
+
rubygems_version: 1.6.2
|
|
143
179
|
signing_key:
|
|
144
180
|
specification_version: 3
|
|
145
181
|
summary: Ruby compiler and runtime for the google protocol buffers library.
|
|
146
|
-
test_files:
|
|
182
|
+
test_files:
|
|
147
183
|
- spec/compiler_spec.rb
|
|
148
184
|
- spec/fields_spec.rb
|
|
149
185
|
- spec/proto_files/depends.proto
|
|
186
|
+
- spec/proto_files/dotted_package.proto
|
|
150
187
|
- spec/proto_files/featureful.proto
|
|
151
188
|
- spec/proto_files/no_package.proto
|
|
152
189
|
- spec/proto_files/simple.proto
|
|
153
190
|
- spec/proto_files/top_level_enum.proto
|
|
191
|
+
- spec/proto_files/under_score_package.proto
|
|
154
192
|
- spec/runtime_spec.rb
|
|
155
193
|
- spec/spec.opts
|
|
156
194
|
- spec/spec_helper.rb
|