Module: RBCliTool

Defined in:
lib/rbcli-tool.rb,
lib/rbcli-tool/util.rb,
lib/rbcli-tool/project.rb,
lib/rbcli-tool/generators.rb

Defined Under Namespace

Classes: Command, ERBRenderer, Extern, Generator, Hook, Project

Class Method Summary collapse

Class Method Details

.continue_confirmation(text) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rbcli-tool/util.rb', line 34

def self.continue_confirmation text
	puts text
	print "Continue? (Y/n):  "
	input = gets
	unless input[0].downcase == 'y'
		puts "\n Aborting..."
		exit 0
	end
end

.cp_file(src, dest, template_vars = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rbcli-tool/util.rb', line 15

def self.cp_file src, dest, template_vars = nil
	dest = "#{dest}#{src.split('/')[-1]}" if dest.end_with? '/'
	if File.exists? dest
		puts "File #{dest} already exists. Please delete it and try again."
	else
		print "Generating file " + dest + " ... "

		if template_vars
			renderer = ERBRenderer.new src, template_vars
			File.open(dest, 'w') {|file| file.write renderer.render}
		else
			FileUtils.cp src, dest
		end

		FileUtils.rm_f "#{File.dirname(dest)}/.keep" if File.exists? "#{File.dirname(dest)}/.keep"
		puts "Done!"
	end
end

.exit_with_error(text) ⇒ Object



44
45
46
47
# File 'lib/rbcli-tool/util.rb', line 44

def self.exit_with_error text
	puts text
	exit 1
end