yellow-brick-road 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,8 @@ require 'yellow-brick-road/utils'
4
4
  begin
5
5
  require 'protobuf-closure-library'
6
6
  require 'yellow-brick-road/protobuf_js'
7
+ require 'yellow-brick-road/protobuf_rb'
8
+ require 'yellow-brick-road/protobuf_compiler'
7
9
  rescue LoadError
8
10
  end
9
11
  require 'yellow-brick-road/directive_processor'
@@ -54,9 +54,11 @@ module YellowBrickRoad
54
54
 
55
55
  mattr_accessor :protos_dir
56
56
  mattr_accessor :protos_js_out_dir
57
+ mattr_accessor :protos_rb_out_dir
57
58
  def self.initProtos
58
59
  @@protos_dir ||= Rails.root.join 'app', 'protos', '**', '*.proto'
59
60
  @@protos_js_out_dir ||= Rails.root.join 'app', 'assets', 'javascripts', 'protos'
61
+ @@protos_rb_out_dir ||= Rails.root.join 'app', 'protos'
60
62
  end
61
63
 
62
64
  mattr_accessor :protobuf_js_superclass
@@ -0,0 +1,17 @@
1
+ module YellowBrickRoad
2
+ @@protobuf_enabled = true
3
+
4
+ def self.compile_protos logger = Rails.logger
5
+ YellowBrickRoad.initProtos
6
+ proto_files = Dir[YellowBrickRoad.protos_dir]
7
+
8
+ if proto_files.empty?
9
+ logger.info "No protobuf file to compile in #{YellowBrickRoad.protos_dir}."
10
+ return
11
+ end
12
+
13
+ compile_protos_to_js proto_files, logger
14
+ compile_protos_to_rb proto_files, logger
15
+ end
16
+
17
+ end
@@ -1,16 +1,8 @@
1
1
 
2
2
  module YellowBrickRoad
3
- @@protobuf_enabled = true
4
3
  include ProtobufClosureLibrary
5
4
 
6
- def self.compile_protos logger = Rails.logger
7
- YellowBrickRoad.initProtos
8
- proto_files = Dir[YellowBrickRoad.protos_dir]
9
-
10
- if proto_files.empty?
11
- logger.info "No protobuf file to compile in #{YellowBrickRoad.protos_dir}."
12
- return
13
- end
5
+ def self.compile_protos_to_js proto_files, logger = Rails.logger
14
6
 
15
7
  generator_options = {}
16
8
  if YellowBrickRoad.protobuf_js_superclass
@@ -20,13 +12,15 @@ module YellowBrickRoad
20
12
  generator_options[:advanced] = 'true'
21
13
  end
22
14
 
23
- logger.info 'Compiling protobuf to closure-library javascript:'
15
+ logger.info '* Compiling protobuf to closure-library javascript:'
16
+
24
17
  proto_files.each do |proto_file|
25
18
  logger.info "\t- #{proto_file}"
26
19
  ProtocJs.compile proto_file, YellowBrickRoad.protos_js_out_dir,
27
20
  generator_options: generator_options
28
21
  end
29
- logger.info "Compiled all to #{YellowBrickRoad.protos_js_out_dir}"
22
+
23
+ logger.info "\tCompiled all to javascript in #{YellowBrickRoad.protos_js_out_dir}"
30
24
  end
31
25
 
32
26
  end
@@ -0,0 +1,39 @@
1
+ require 'protocol_buffers'
2
+ require 'protocol_buffers/compiler'
3
+ require 'protocol_buffers/compiler/file_descriptor_to_ruby'
4
+ require 'tempfile'
5
+
6
+ module YellowBrickRoad
7
+
8
+ def self.compile_protos_to_rb proto_files, logger = Rails.logger
9
+ include_dirs = proto_files.map { |proto_file| File.dirname proto_file }
10
+ include_dirs.uniq!
11
+
12
+ protocfile = Tempfile.new 'ruby-protoc'
13
+ protocfile.binmode
14
+ ProtocolBuffers::Compiler.compile protocfile.path, proto_files,
15
+ :include_dirs => include_dirs
16
+ descriptor_set = FileDescriptorSet.parse protocfile
17
+ protocfile.close true
18
+
19
+ logger.info '* Compiling protobuf to ruby:'
20
+
21
+ descriptor_set.file.each do |file_descriptor|
22
+ proto_file = proto_files[proto_files.index { |path| path.include? file_descriptor.name }]
23
+ logger.info "\t- #{proto_file}"
24
+
25
+ path = File.join YellowBrickRoad.protos_rb_out_dir,
26
+ File.basename(file_descriptor.name, '.proto') + '.pb.rb'
27
+
28
+ FileUtils.mkpath(File.dirname(path)) unless File.directory?(File.dirname(path))
29
+
30
+ File.open(path, "wb") do |file|
31
+ dumper = FileDescriptorToRuby.new(file_descriptor)
32
+ dumper.write(file)
33
+ end
34
+ end
35
+
36
+ logger.info "\tCompiled all to ruby in #{YellowBrickRoad.protos_js_out_dir}"
37
+ end
38
+
39
+ end
@@ -1,3 +1,3 @@
1
1
  module YellowBrickRoad
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yellow-brick-road
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2152614120 !ruby/object:Gem::Requirement
16
+ requirement: &2168934540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152614120
24
+ version_requirements: *2168934540
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-protocol-buffers
27
+ requirement: &2168934080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2168934080
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: sqlite3
27
- requirement: &2152613700 !ruby/object:Gem::Requirement
38
+ requirement: &2168933600 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *2152613700
46
+ version_requirements: *2168933600
36
47
  description: ! " A set of tools for integrating google closure library into rails,
37
48
  including:\n Automatic dependency generation of a closure library based application,\n
38
49
  \ using soy templates both as standalone and as part of the closure library,\n
@@ -49,7 +60,9 @@ files:
49
60
  - lib/yellow-brick-road/config.rb
50
61
  - lib/yellow-brick-road/directive_processor.rb
51
62
  - lib/yellow-brick-road/engine.rb
63
+ - lib/yellow-brick-road/protobuf_compiler.rb
52
64
  - lib/yellow-brick-road/protobuf_js.rb
65
+ - lib/yellow-brick-road/protobuf_rb.rb
53
66
  - lib/yellow-brick-road/soy_processor.rb
54
67
  - lib/yellow-brick-road/utils.rb
55
68
  - lib/yellow-brick-road/version.rb
@@ -439,7 +452,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
439
452
  version: '0'
440
453
  segments:
441
454
  - 0
442
- hash: 4395823193007168051
455
+ hash: 3356618062880120890
443
456
  required_rubygems_version: !ruby/object:Gem::Requirement
444
457
  none: false
445
458
  requirements:
@@ -448,7 +461,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
448
461
  version: '0'
449
462
  segments:
450
463
  - 0
451
- hash: 4395823193007168051
464
+ hash: 3356618062880120890
452
465
  requirements: []
453
466
  rubyforge_project:
454
467
  rubygems_version: 1.8.10