Class: RBCliTool::Hook

Inherits:
Generator show all
Defined in:
lib/rbcli-tool/generators.rb

Instance Method Summary collapse

Methods inherited from Generator

inherited

Constructor Details

#initialize(root_path, hook_type) ⇒ Hook

Returns a new instance of Hook.



65
66
67
68
69
70
71
72
73
74
# File 'lib/rbcli-tool/generators.rb', line 65

def initialize root_path, hook_type
	@typename = {
			default: 'default_action',
			pre: 'pre_execution',
			post: 'post_execution',
			firstrun: 'first_run'
	}[hook_type]
	@src = "#{File.dirname(__FILE__)}/../../skeletons/project/hooks/#{@typename}.rb"
	@dest = "#{root_path}/hooks/#{@typename}.rb"
end

Instance Method Details

#run ⇒ Object



76
77
78
79
80
81
82
# File 'lib/rbcli-tool/generators.rb', line 76

def run
	if File.exists? @dest
		RBCliTool.continue_confirmation "The #{@typename} hook already exists; contents will be overwritten."
		FileUtils.rm_rf @dest
	end
	RBCliTool.cp_file @src, @dest
end