Class: RBCliTool::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcli-tool/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, template_vars = {}) ⇒ Project

Returns a new instance of Project.



4
5
6
7
8
9
10
11
# File 'lib/rbcli-tool/project.rb', line 4

def initialize path, template_vars = {}
	@skelpath = "#{File.dirname(__FILE__)}/../../skeletons/project"
	@minipath = "#{File.dirname(__FILE__)}/../../skeletons/mini/executable"
	@micropath = "#{File.dirname(__FILE__)}/../../skeletons/micro/executable"

	@dest = path
	@template_vars = template_vars
end

Class Method Details

.find_root(path) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/rbcli-tool/project.rb', line 69

def self.find_root path
	# We look for the .rbcli file in the current tree and return the root path
	searchpath = path
	while !searchpath.empty?
		return searchpath if File.directory? searchpath and File.exists? "#{searchpath}/.rbcli"
		spath = searchpath.split('/')
		searchpath = (spath.length == 2) ? '/' : spath[0..-2].join('/')
	end
	false
end

Instance Method Details

#create(force = false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rbcli-tool/project.rb', line 13

def create force = false
	return false if project_exists? and not force
	src = @skelpath

	# Create Top Level Folder (TLF)
	FileUtils.mkdir_p @dest

	# Create project structure
	%w(
		application/commands
		application/commands/scripts
		config
		default_user_configs
		exe
		hooks
		spec
	).each do |folder|
		FileUtils.mkdir_p "#{@dest}/#{folder}"
		FileUtils.touch "#{@dest}/#{folder}/.keep"
	end

	# Create executable
	RBCliTool.cp_file "#{src}/exe/executable", "#{@dest}/exe/#{@template_vars[:cmdname]}", @template_vars
	FileUtils.chmod 0755, "#{@dest}/exe/#{@template_vars[:cmdname]}"

	# Create files for Gem package
	Dir.entries(src).each do |file|
		next if File.directory? "#{src}/#{file}"
		RBCliTool.cp_file "#{src}/#{file}", "#{@dest}/", @template_vars
	end

	# Create default config
	Dir.glob "#{src}/config/*.rb" do |file|
		RBCliTool.cp_file file, "#{@dest}/config/", @template_vars
	end

	# Create application options
	RBCliTool.cp_file "#{src}/application/options.rb", "#{@dest}/application/options.rb", @template_vars

	true
end

#create_micro(force = false) ⇒ Object



60
61
62
63
# File 'lib/rbcli-tool/project.rb', line 60

def create_micro force = false
	return false if project_exists? and not force
	RBCliTool.cp_file @micropath, @dest, @template_vars
end

#create_mini(force = false) ⇒ Object



55
56
57
58
# File 'lib/rbcli-tool/project.rb', line 55

def create_mini force = false
	return false if project_exists? and not force
	RBCliTool.cp_file @minipath, @dest, @template_vars
end

#exists? ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rbcli-tool/project.rb', line 65

def exists?
	project_exists?
end