Project-file generation tasks
Flags to use when opening a file for generation
Template files
RVM metadata files
Define generation tasks.
# File lib/rake/deveiate/generate.rb, line 27
def define_tasks
super if defined?( super )
file( self.rakefile.to_s )
file( self.readme_file.to_s )
file( self.history_file.to_s )
file( self.manifest_file.to_s )
file( RUBY_VERSION_FILE.to_s )
file( GEMSET_FILE.to_s )
task( self.rakefile, &method(:do_generate_rakefile) )
task( self.readme_file, &method(:do_generate_readme_file) )
task( self.history_file, &method(:do_generate_history_file) )
task( self.manifest_file, &method(:do_generate_manifest_file) )
task( RUBY_VERSION_FILE, &method(:do_generate_ruby_version_file) )
task( GEMSET_FILE, &method(:do_generate_gemset_file) )
desc "Generate any missing project files."
task :generate => [
self.rakefile,
self.readme_file,
self.history_file,
self.manifest_file,
RUBY_VERSION_FILE,
GEMSET_FILE,
]
# Abstract named tasks; mostly for invoking programmatically
namespace :generate do
task :rakefile => self.rakefile
task :readme => self.readme_file
task :history_file => self.history_file
task :manifest => self.manifest_file
task :ruby_version_file => RUBY_VERSION_FILE
task :gemset_file => GEMSET_FILE
end
desc "Diff the manifest file against the default set of project files."
task( :diff_manifest, &method(:do_diff_manifest) )
end
Task body for the `diff_manifest` task
# File lib/rake/deveiate/generate.rb, line 116
def do_diff_manifest( task, args )
Tempfile.open( ['Manifest','.txt'], Rake::DevEiate::PROJECT_DIR ) do |io|
file_list = self.default_manifest.to_a
io.puts( *file_list )
io.flush
sh 'diff', '-ub', self.manifest_file.to_s, io.path
end
end
Generate
a file that sets the project's gemset
# File lib/rake/deveiate/generate.rb, line 107
def do_generate_gemset_file( task, args )
self.prompt.ok "Generating #{task.name}..."
File.open( task.name, FILE_CREATION_FLAGS, 0644, encoding: 'utf-8' ) do |io|
io.puts( self.name )
end
end
Generate
a manifest with a default set of files listed.
# File lib/rake/deveiate/generate.rb, line 89
def do_generate_manifest_file( task, args )
self.prompt.ok "Generating #{task.name}..."
File.open( task.name, FILE_CREATION_FLAGS, 0644, encoding: 'utf-8' ) do |io|
io.puts( *self.project_files )
end
end
Generate
a Rakefile if one doesn't already exist. Error if one does.
# File lib/rake/deveiate/generate.rb, line 70
def do_generate_rakefile( task, args )
self.generate_from_template( task.name, RAKEFILE_TEMPLATE )
end
Generate
a file that sets the project's working Ruby version.
# File lib/rake/deveiate/generate.rb, line 98
def do_generate_ruby_version_file( task, args )
self.prompt.ok "Generating #{task.name}..."
File.open( task.name, FILE_CREATION_FLAGS, 0644, encoding: 'utf-8' ) do |io|
io.puts( RUBY_VERSION.sub(/\.\d+$/, '') )
end
end
Generate
the given filename
from the template filed at template_path
.
# File lib/rake/deveiate/generate.rb, line 128
def generate_from_template( filename, template_path )
self.prompt.ok "Generating #{filename}..."
File.open( filename, FILE_CREATION_FLAGS, 0644, encoding: 'utf-8' ) do |io|
result = self.load_and_render_template( template_path, filename )
io.print( result )
end
end