Rake::DevEiate::

Generate

module

Project-file generation tasks

Constants

FILE_CREATION_FLAGS

Flags to use when opening a file for generation

GEMSET_FILE
HISTORY_TEMPLATE
RAKEFILE_TEMPLATE

Template files

README_TEMPLATE
RUBY_VERSION_FILE

RVM metadata files

Public Instance Methods

anchor
define_tasks()

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
anchor
do_diff_manifest( task, args )

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
anchor
do_generate_gemset_file( task, args )

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
anchor
do_generate_history_file( task, args )

Generate a History file if one doesn't already exist. Error if one does.

# File lib/rake/deveiate/generate.rb, line 83
def do_generate_history_file( task, args )
        self.generate_from_template( task.name, HISTORY_TEMPLATE )
end
anchor
do_generate_manifest_file( task, args )

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
anchor
do_generate_rakefile( task, args )

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
anchor
do_generate_readme_file( task, args )

Generate a README file if one doesn't already exist. Error if one does.

# File lib/rake/deveiate/generate.rb, line 76
def do_generate_readme_file( task, args )
        self.generate_from_template( task.name, README_TEMPLATE )
end
anchor
do_generate_ruby_version_file( task, args )

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
anchor
generate_from_template( filename, template_path )

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