class Temp::Project
A Project
object represents a project and provides a method for copying the files from a template to create a project.
Attributes
name[R]
path[R]
template[R]
Public Class Methods
new(path, template)
click to toggle source
Initialize all the required information for creating the project and make sure the project doesn't already exist
# File lib/temp/project.rb, line 14 def initialize(path, template) @path = File.expand_path(path) @template = template if File.file? @path raise Temp::Exceptions::ProjectExistsError elsif File.directory? @path @name = @template.filename @path = File.join(@path, @name) raise Temp::Exceptions::ProjectExistsError if File.exist? @path else @name = File.basename(@path) end end
Public Instance Methods
create()
click to toggle source
Create the project
# File lib/temp/project.rb, line 29 def create if File.file? @template.path FileUtils.cp(@template.path, @path) else FileUtils.mkdir_p(path) (@template.files - @template.tempfile.ignore_files).each do |file| t_file = File.join(@template.path, file) p_file = File.join(@path, file) if File.file? t_file if @template.tempfile.erb_files.include? file renderer = ERB.new(File.read(t_file)) File.open(p_file, 'w') { |f| f.write renderer.result(@template.tempfile.get_binding) } else FileUtils.cp(t_file, p_file) end else Dir.mkdir(p_file) end end end end