Module: Tetra::ProjectIniter::ClassMethods
- Defined in:
- lib/tetra/project_initer.rb
Overview
class methods container
Instance Method Summary collapse
-
#init(dir, include_bundled_software = true) ⇒ Object
inits a new project directory structure.
-
#project?(dir) ⇒ Boolean
returns true if the specified directory is a valid tetra project.
Instance Method Details
#init(dir, include_bundled_software = true) ⇒ Object
inits a new project directory structure
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tetra/project_initer.rb', line 30 def init(dir, include_bundled_software = true) Dir.mkdir(dir) # Avoid Dir.chdir(dir). Use absolute paths instead. # Initialize Git facade with the full path git = Tetra::Git.new(dir) git.init FileUtils.mkdir_p(File.join(dir, "src")) FileUtils.mkdir_p(File.join(dir, "kit")) # Create a project instance (now that the dir structure exists) project = Project.new(dir) project.template_files(include_bundled_software).each do |source, destination| # Source is relative to TEMPLATE_PATH src_path = File.join(TEMPLATE_PATH, source) # Destination is relative to the new project directory dst_path = File.join(dir, destination) FileUtils.cp_r(src_path, dst_path) end # Commit "." (Git facade handles context, "." means "all changes in repo") git.commit_directories(["."], "Template files added") end |
#project?(dir) ⇒ Boolean
returns true if the specified directory is a valid tetra project
19 20 21 22 23 24 25 26 27 |
# File 'lib/tetra/project_initer.rb', line 19 def project?(dir) # Use a block for logging so we don't list files unless debug is on. # Dir.children is faster/cleaner than Dir.new(dir).to_a Tetra::Logger.instance.debug { "Checking for tetra project: #{dir}, contents: #{Dir.children(dir)}" } File.directory?(File.join(dir, "src")) && File.directory?(File.join(dir, "kit")) && File.directory?(File.join(dir, ".git")) end |