Class: RBCliTool::Project
- Inherits:
-
Object
- Object
- RBCliTool::Project
- Defined in:
- lib/rbcli-tool/project.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(force = false) ⇒ Object
- #create_micro(force = false) ⇒ Object
- #create_mini(force = false) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(path, template_vars = {}) ⇒ Project
constructor
A new instance of Project.
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
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rbcli-tool/project.rb', line 98 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 79 80 81 82 |
# 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/#{@template_vars[:cmdname]} ).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 # Create lib file RBCliTool.cp_file "#{src}/lib/lib.erb", "#{@dest}/lib/#{@template_vars[:cmdname]}.rb", @template_vars FileUtils.rm_f "#{@dest}/lib/.keep" true end |
#create_micro(force = false) ⇒ Object
89 90 91 92 |
# File 'lib/rbcli-tool/project.rb', line 89 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
84 85 86 87 |
# File 'lib/rbcli-tool/project.rb', line 84 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
94 95 96 |
# File 'lib/rbcli-tool/project.rb', line 94 def exists? project_exists? end |