protip 0.20.1 → 0.20.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/protip/tasks/compile.rake +60 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9a530ecc12160b36bb16eace8ff4d684ef30eae
4
- data.tar.gz: 165e373d6d3931574b1b3891379204af6cd6f7d7
3
+ metadata.gz: 2250fc4ff6bdcd6d69c30c369da5a6934d8458b9
4
+ data.tar.gz: 96844a4c73302bcebbea6c429d4cdab57f855a70
5
5
  SHA512:
6
- metadata.gz: f0a869ac73a101dde2c45735361166f90eb3466ec5b8b81f4befbb17a1607b0c4ff077f10ee270988ddffae022f34eb904ec2ba52efe74f62b5e263a6f931c3b
7
- data.tar.gz: 2da3112ab256949d3cad42f7ed804c15b0baa2d8aa12f91a50c06773fc449ff51c3a43d2fa2dcdfc1bcd3c44b5342d4b47890ffeeff17315fb151a53854c1f4b
6
+ metadata.gz: aa3294f1b6d92f0aa0fccb7fc238f5e07ec63edbf5e4aa4c3fbab2dc318867bc39bdd863c21e598959bbdecce3e8822c703f829e676bdff6ad8d5c5810c47f59
7
+ data.tar.gz: 8f81ffd115d480d25e831e8b982ca4097a9f44f0273934bcabee3b60fc829e2394ee60eb8d075c5cbe98a390bd58239ae60c45503e119b67ade0ce81e47f3710
@@ -0,0 +1,60 @@
1
+ require 'shellwords'
2
+ namespace :protip do
3
+ desc 'compile a single .proto file to Ruby'
4
+ task :compile, [:filename, :proto_path, :ruby_path] do |t, args|
5
+ proto_path = [args[:proto_path] || 'definitions'].flatten.compact.reject{|path| path == ''}
6
+ proto_path << File.join(Gem.loaded_specs['protip'].full_gem_path, 'definitions')
7
+
8
+ ruby_path = args[:ruby_path] || 'lib'
9
+
10
+ filename = args[:filename] || raise(ArgumentError.new 'filename argument is required')
11
+
12
+ command = "protoc #{proto_path.map{|p| "--proto_path=#{Shellwords.escape p}"}.join ' '} --ruby_out=#{Shellwords.escape ruby_path} #{Shellwords.escape filename}"
13
+ puts command # is there a better way to log this?
14
+ system command
15
+
16
+ ## hack around missing options in Ruby, remove when https://github.com/google/protobuf/issues/1198 is resolved
17
+ package_match = File.read(filename).match(/package "?([a-zA-Z0-9\.]+)"?;/)
18
+ package = (package_match ? package_match[1] : nil)
19
+ ruby_file = filename.gsub(/^#{proto_path.first}\/?/, "#{ruby_path}/").gsub(/proto$/, 'rb') # Relies on a relative filename and proto path, which protoc requires anyway at this point
20
+ raise "cannot find generated Ruby file (#{ruby_file})" unless File.exists?(ruby_file)
21
+
22
+ # Push/pop message names as we move through the protobuf file
23
+ message_name_stack = []
24
+ first_match = true
25
+ File.open filename, 'r' do |f|
26
+ f.each_line do |line|
27
+ if line.include? '{'
28
+ match = line.match(/message\s([a-zA-Z]+)/)
29
+ message_name_stack << (match ? match[1] : nil)
30
+ end
31
+
32
+ # figure out the field name and enum name if this line is like
33
+ # +protip.messages.EnumValue value = 3 [(protip_enum) = "Foo"]+
34
+ match = line.match /\s*[a-zA-Z0-9\.]+\s+([a-zA-Z0-9]+).+\[\s*\(\s*protip_enum\s*\)\s*=\s*"([a-zA-Z0-9\.]+)"\s*\]/
35
+ if match
36
+ message_name = "#{package ? "#{package}." : ''}#{message_name_stack.compact.join('.')}"
37
+ field_name = match[1]
38
+ enum_name = match[2]
39
+ File.open ruby_file, 'a' do |f|
40
+ if first_match
41
+ f.puts <<-RBY
42
+
43
+ # -- Protip hack until https://github.com/google/protobuf/issues/1198 is resolved
44
+ RBY
45
+ end
46
+ first_match = false
47
+ f.puts <<-RBY
48
+ Google::Protobuf::DescriptorPool.generated_pool.lookup("#{message_name}").lookup("#{field_name}").instance_variable_set(:"@_protip_enum_value", "#{enum_name}")
49
+ RBY
50
+ end
51
+ end
52
+
53
+ if line.include? '}'
54
+ message_name_stack.pop
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AngelList
@@ -219,6 +219,7 @@ files:
219
219
  - lib/protip/resource/search_methods.rb
220
220
  - lib/protip/resource/updateable.rb
221
221
  - lib/protip/standard_converter.rb
222
+ - lib/protip/tasks/compile.rake
222
223
  - lib/protip/wrapper.rb
223
224
  - test/functional/protip/resource_test.rb
224
225
  - test/test_helper.rb