Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to have require_relative statements #377

Merged
merged 1 commit into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/protobuf/generators/file_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def print_import_requires
header "Imports"

descriptor.dependency.each do |dependency|
print_require(convert_filename(dependency))
print_require(convert_filename(dependency), ENV.key?('PB_REQUIRE_RELATIVE'))
end

puts
Expand Down
4 changes: 2 additions & 2 deletions lib/protobuf/generators/printable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def print_module(name, &block)
#
# print_require('foo/bar/baz') -> "require 'foo/bar/baz'"
#
def print_require(file)
puts "require '#{file}'"
def print_require(file, relative = false)
puts "require#{'_relative' if relative} '#{file}'"
end

# Puts the given message prefixed by the indent level.
Expand Down
11 changes: 9 additions & 2 deletions spec/lib/protobuf/generators/file_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@
end

it 'prints a ruby require for each dependency' do
expect(subject).to receive(:print_require).with('test/bar.pb')
expect(subject).to receive(:print_require).with('test/baz.pb')
expect(subject).to receive(:print_require).with('test/bar.pb', false)
expect(subject).to receive(:print_require).with('test/baz.pb', false)
subject.print_import_requires
end

it 'prints a ruby require_relative for each dependency if environment variable was set' do
expect(subject).to receive(:print_require).with('test/bar.pb', true)
expect(subject).to receive(:print_require).with('test/baz.pb', true)
ENV['PB_REQUIRE_RELATIVE'] = 'true'
subject.print_import_requires
ENV.delete('PB_REQUIRE_RELATIVE')
end
end

describe '#compile' do
Expand Down