Class: RBCliTool::Project

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

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

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
# 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

  # 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



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

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



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

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)


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

def exists?
  project_exists?
end