fgrehm / vagrant-cachier

Caffeine reducer
http://fgrehm.viewdocs.io/vagrant-cachier
MIT License
1.08k stars 111 forks source link

fix compatibility with ruby 1.9.3 #91

Closed tknerr closed 10 years ago

tknerr commented 10 years ago

When using vagrant-cachier in a Ruby 1.9.3 environment I get his error:

D:\Repos\_github\vagrant-managed-servers>bundle exec vagrant destroy -f fake_managed_server
W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/action/install_buckets.rb:1:in `require_relative': W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/bucket.rb:46: syntax error, unexpected tLABEL (SyntaxError)
...cache/#{@name}", create_parent: true)
...                               ^
W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/bucket.rb:88: syntax error, unexpected keyword_end, expecting $end
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/action/install_buckets.rb:1:in `<top (required)>'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/hooks.rb:6:in `require_relative'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/vagrant-cachier-0.6.0/lib/vagrant-cachier/hooks.rb:6:in `block in <class:Plugin>'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:45:in `call'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:45:in `block (2 levels) in run'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:44:in `tap'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:44:in `block in run'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:43:in `map'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/action/runner.rb:43:in `run'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/environment.rb:283:in `hook'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/lib/vagrant/environment.rb:139:in `initialize'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/bin/vagrant:105:in `new'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bundler/gems/vagrant-4f0eb9504cc7/bin/vagrant:105:in `<top (required)>'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bin/vagrant:23:in `load'
        from W:/tools/ruby-1.9.3/lib/ruby/gems/1.9.1/bin/vagrant:23:in `<main>'

I believe the create_parent: true syntax works for Ruby 2.0.0 but not for 1.9.3. Switching to create_parent = true fixes the problem.

P.S.: I'm getting this while developing a vagrant plugin with my 1.9.3 system ruby.

fgrehm commented 10 years ago

The 0.6.0 version of the plugin should only be compatible with Vagrant 1.4+ which comes with Ruby 2.0, so I strongly recommend upgrading to 2.0 if you can.

I'm ok with bringing these changes in but we need to double check that all buckets will keep working fine. From the top of my head, I believe that the composer bucket is the only one using that, but we might not need that parameter anymore after we fix GH-89

tknerr commented 10 years ago

Yep I checked that first because I was surprised whether it would work with Vagrant 1.3 (comes with Ruby 1.9.3), but then saw the mention in the CHANGELOG.

I was not sure whether it was implemented as a keyword arg intentionally, because the way it is used looked like it would be simply an optional arg with default.

Given my humble ruby skills I would say the implementation is equivalent, but I haven't explicitly tested all the buckets yet.

Btw: rake spec:unit did not work for me (rake reported don't know how to run this task or similar). Is this because there is no spec/unit?

tknerr commented 10 years ago

@fgrehm you are right, it will possibly break the composer bucket, which seems to be the only one using create_parent atm: https://github.com/fgrehm/vagrant-cachier/blob/master/lib/vagrant-cachier/bucket/composer.rb#L12

I'm closing this PR rather than breaking existing functionality, I wanted to switch to Ruby 2.0 anyway...

fgrehm commented 10 years ago

I was not sure whether it was implemented as a keyword arg intentionally, because the way it is used looked like it would be simply an optional arg with default.

Yes it was intentional and yes it could be an optional arg with default, I think that is some leftover from some experimenting I did on a recent irresponsible refactoring :smiley:

Btw: rake spec:unit did not work for me (rake reported don't know how to run this task or similar). Is this because there is no spec/unit?

Oh, I probably copy & pasted that Rakefile from some other project, it's been around since the first public release :open_mouth:. Well, unfortunately there are currently no unit specs, just a set of Bats sanity checks