Class: Ramaze::Tool::Create
Overview
Create is a simple class used to create new projects based on the proto directory.
It is primarly used for this command:
ramaze --create project
where project is the directory you want the content put into.
Class Method Summary collapse
-
.copy_files(*files) ⇒ Object
copy the files over.
-
.create(project) ⇒ Object
a method to create a new project by copying the contents of lib/proto to the position you specify (project).
-
.create_dirs(*dirs) ⇒ Object
create the directories recursivly.
Class Method Details
.copy_files(*files) ⇒ Object
copy the files over
63 64 65 66 67 68 69 70 |
# File 'lib/ramaze/tool/create.rb', line 63 def copy_files(*files) files.each do |file| dest = file.gsub(@basedir, @destdir) puts "Copy file: '#{dest}'" FileUtils.cp(file, dest) end end |
.create(project) ⇒ Object
a method to create a new project by copying the contents of lib/proto to the position you specify (project)
It is just a nice wrapper showing you what files/directories are put in place.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ramaze/tool/create.rb', line 25 def create project @basedir = ::Ramaze::BASEDIR / 'proto' @destdir = Dir.pwd / project if File.directory?(@destdir) puts "Error: #{project}/ already exists. Rename or delete directory and try again." return end puts "Creating project #{project}" FileUtils.mkdir_p(project) puts "Copying skeleton project to new project (#@destdir)..." directories, files = Dir[@basedir / '**' / '*'].partition{ |f| File.directory?(f) } # gem packaging removes empty model directory, so add it in ourselves create_dirs(*Array[ @basedir/'model', *directories ].uniq) copy_files(*files) puts "\nStart your new ramaze app: ruby #{project}/start.rb" end |
.create_dirs(*dirs) ⇒ Object
create the directories recursivly
52 53 54 55 56 57 58 59 |
# File 'lib/ramaze/tool/create.rb', line 52 def create_dirs(*dirs) dirs.each do |dir| dest = dir.gsub(@basedir, @destdir) puts "Create directory: '#{dest}'" FileUtils.mkdir_p(dest) end end |