Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Created January 27, 2012 22:36
Show Gist options
  • Select an option

  • Save stevenharman/1691330 to your computer and use it in GitHub Desktop.

Select an option

Save stevenharman/1691330 to your computer and use it in GitHub Desktop.
A wrapper for running app installer/un-installers, etc.
# An example usage might look something like:
class MyApp
extend Verver::SandboxedExecute
def initialize(options)
# ...
end
# ...
def install!
# run the installer for this kind of app
end
def uninstall!
# run the uninstaller for this kind of app
end
end
MyApp.execute(foo: 'blah', this: 'that') do |instance|
# do interesting things w/the app here.
end
# Is this a really bad idea? Specifically, the private method bit?
# Also, any thoughts on the API?
module Verver
module SandboxedExecute
def execute(install_options={}, &safe_block)
instance = new(install_options)
return unless instance.install!
__execute_in_sandbox(instance, safe_block)
end
private
def __execute_in_sandbox(instance, safe_block)
safe_block.call(instance)
ensure
instance.uninstall!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment