Class: RBCliTool::Extern

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, template_vars) ⇒ Extern

Returns a new instance of Extern.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbcli-tool/generators.rb', line 34

def initialize root_path, template_vars
	@filepaths = [
			{
					src: "#{File.dirname(__FILE__)}/../../skeletons/project/application/commands/script.erb",
					dest: "#{root_path}/application/commands/#{template_vars[:name]}.rb"
			}, {
					src: "#{File.dirname(__FILE__)}/../../skeletons/project/application/commands/scripts/script.sh",
					dest: "#{root_path}/application/commands/scripts/#{template_vars[:name]}.sh",
					perms: 0755
			}
	]
	@template_vars = template_vars
	#@template_vars[:libsh_path] = Pathname.new("#{File.dirname(__FILE__)}/../../lib-sh/lib-rbcli.sh").cleanpath.to_s  # We clean this path because it will be visible to the user
end

Instance Method Details

#run ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rbcli-tool/generators.rb', line 49

def run
	confirmed = false
	@filepaths.each do |file|
		next if file[:dest].end_with? '.sh' and @template_vars[:no_script]
		if File.exists? file[:dest]
			RBCliTool.continue_confirmation "The script command #{@template_vars[:name]} already exists; contents will be overwritten." unless confirmed
			confirmed = true
			FileUtils.rm_rf file[:dest]
		end
		RBCliTool.cp_file file[:src], file[:dest], @template_vars
		File.chmod file[:perms], file[:dest] if file.key? :perms
	end
end