fluent/fluentd — pull request #190 by sonots (2013-09-06 12:12:53+00:00)
Title: fix -g GEMFILE option

bin/fluentd -g MyGemfile

/home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/ui.rb:36:in `initialize': undefined method `[]' for # (NoMethodError)
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/bundler_injection.rb:33:in `new'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/bundler_injection.rb:33:in `install'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/command/fluentd.rb:162:in `'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from bin/fluentd:5:in `

'

where https://github.com/bundler/bundler/blob/v1.3.5/lib/bundler/ui.rb#L36. The modification of `lib/fluentd/bundler_injection.rb` is to fix the above error. This error was caused because Bundler changed its internal method interface on v1.3.0.

* v1.2.5 https://github.com/bundler/bundler/blob/v1.2.5/lib/bundler/ui.rb#L28
* v1.3.0 https://github.com/bundler/bundler/blob/v1.3.0/lib/bundler/ui.rb#L34
* at https://github.com/bundler/bundler/commit/d5e8d58999b450ec289b1231610674c2dac70e21#lib/bundler/ui.rb

Next, I met with another error.
bin/fluentd -g MyGemfile

/home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions/create_file.rb:33:in `': uninitialized constant Thor::Actions::EmptyDirectory (NameError)
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions/create_file.rb:4:in `'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions/create_file.rb:3:in `'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions.rb:4:in `require'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions.rb:4:in `'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions/empty_directory.rb:2:in `'
from /home/seo.naotoshi/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/vendor/thor/actions/empty_directory.rb:1:in `'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:177:in `require'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:177:in `block in restore!'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:176:in `each'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:176:in `restore!'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:188:in `restore'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/worker_launcher.rb:73:in `main'
from /home/seo.naotoshi/gitrepos/fluentd_v11/lib/fluentd/command/fluentd-worker.rb:19:in `

'

Seeing values of @loaded_features at `lib/fluentd/worker_launcher.rb`, it seems that this error was caused by order of `require`. By adding `sort`, this problem was fixed.

FINAL THOUGHT:

However, I feel that `-g GEMFILE` functionality is very feasible because it can easily be broken by the change of Bundler's internal interface like this. I also think as `require`ing in alphabetical order does not always assure that `require`ing order is correct.

It would be better to abandon this feature or position this feature as an experimental feature until we find a great solution.