sprinkle-tool / sprinkle

Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails, or Sinatra stack on a brand new slice directly after its been created
https://github.com/sprinkle-tool/sprinkle
MIT License
1.15k stars 138 forks source link

Creating a 'test' deployer inline with sprinkle script #172

Closed dekz closed 11 years ago

dekz commented 11 years ago

It doesn't seem to be possible to monkey patch or declare new classes inline to the sprinkle script.

Here is a gist with a reproducible file.

A work around for me is to use a script which programatically executes Sprinkle, similar to the way ./bin/sprinkle does:

require 'sprinkle'

module Sprinkle
  module Actors
    class Test < Dummy
    end
  end
end

powder = './install.rb'
Sprinkle::Script.sprinkle File.read(powder), powder

What are your thoughts on this situation? Is there any other way to do this?

joshgoebel commented 11 years ago

Did you try adding :: to all the classes to make sure you're getting to the top scope:

module ::Sprinkle
  module Actors
    class Test < Dummy
    end
  end
end
dekz commented 11 years ago

That seems to fix it, cheers Josh. It also works fine when required.

joshgoebel commented 11 years ago

The scope of everything is different when Sprinkle is reading the file itself... so if you truly want the top-level class you have to make sure you add ::... otherwise you're just trying to access Sprinkle inside of another smaller scope - where no Sprinkle exists.