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.



85
86
87
88
89
90
91
92
93
94
# File 'lib/rbcli-tool/generators.rb', line 85

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

#runObject



96
97
98
99
100
101
102
# File 'lib/rbcli-tool/generators.rb', line 96

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