-
-
Save lazyatom/169002 to your computer and use it in GitHub Desktop.
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
module Rip | |
module Commands | |
# Runs ~/.rip/active/hooks/after-use after `rip use` | |
# and ~/.rip/active/hooks/on-leave when moving to another env | |
alias_method :rip_use, :use | |
def use(*args) | |
run_hook_if_exists('before-leave') | |
rip_use(*args) | |
run_hook_if_exists('after-use') | |
end | |
o 'rip hooks [edit|show] NAME' | |
x 'Show or display hooks from the current environment' | |
def hooks(options = {}, command = 'show', name = nil) | |
if command == 'show' | |
if name | |
puts File.read(path_to_hook(name)) | |
else | |
available_hooks = Dir[hook_dir + "/*"].map { |f| File.basename(f) } | |
ui.abort "Please state which hook you want to show (available hooks: #{available_hooks.join(", ")})" | |
end | |
elsif command == 'edit' | |
ui.abort "Please provide a hook to edit (i.e. after-use)" unless name | |
exec "$EDITOR #{path_to_hook(name)}" | |
end | |
end | |
private | |
def run_hook_if_exists(name) | |
hook = path_to_hook(name) | |
exec hook if File.exists?(hook) && File.executable?(hook) | |
end | |
def path_to_hook(name) | |
File.join(hook_dir, name) | |
end | |
def hook_dir | |
File.join(Rip::Env.active_dir, 'rip-hooks') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment