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.



24
25
26
27
28
29
30
31
# File 'lib/rbcli-tool/project.rb', line 24

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



94
95
96
97
98
99
100
101
102
103
# File 'lib/rbcli-tool/project.rb', line 94

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rbcli-tool/project.rb', line 33

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
    userconf
    exe
    hooks
    spec
    lib
  ).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}"
    if file == "untitled.gemspec"
      RBCliTool.cp_file "#{src}/#{file}", "#{@dest}/#{@template_vars[:cmdname]}.gemspec", @template_vars
    else
      RBCliTool.cp_file "#{src}/#{file}", "#{@dest}/", @template_vars
    end
  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



85
86
87
88
# File 'lib/rbcli-tool/project.rb', line 85

def create_micro force = false
  return false if project_exists? and not force
  RBCliTool.cp_file @micropath, "#{@dest}/#{@template_vars[:cmdname]}", @template_vars
end

#create_mini(force = false) ⇒ Object



80
81
82
83
# File 'lib/rbcli-tool/project.rb', line 80

def create_mini force = false
  return false if project_exists? and not force
  RBCliTool.cp_file @minipath, "#{@dest}/#{@template_vars[:cmdname]}", @template_vars
end

#exists?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/rbcli-tool/project.rb', line 90

def exists?
  project_exists?
end