Created
January 27, 2012 22:36
-
-
Save stevenharman/1691330 to your computer and use it in GitHub Desktop.
A wrapper for running app installer/un-installers, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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