Rake::DevEiate::

Fixup

module
Extended With
Rake::DSL

Fixup and conversion tasks

Constants

BUNDLER_FILES

Pathnames of Bundler-related files

DEV_GEMDEPS

Gems to add to the 'development' group of the deps file

LEGACY_DEPSFILES

Pathnames of legacy dependency files

MANIFEST_CRUFT_LINE

Pattern for matching lines in the Manifest that shouldn't be there

Public Instance Methods

anchor
bundler_files_present?()

Return true if there are Bundler-related files in the project.

# File lib/rake/deveiate/fixup.rb, line 127
def bundler_files_present?
        return BUNDLER_FILES.any?( &:exist? )
end
anchor
define_hoe_fixup_tasks()

Set up tasks that check for poor whitespace discipline

# File lib/rake/deveiate/fixup.rb, line 51
def define_hoe_fixup_tasks

        desc "Perform various fixup tasks on the current project."
        task :fixup => 'fixup:all'

        namespace :fixup do

                task :all => [
                        :rakefile,
                        :manifest,
                        :bundler,
                        :depsfiles,
                ]

                desc "Remove hoe from the Rakefile and re-generate it"
                task :rakefile, &method( :do_fixup_rakefile )


                desc "Clean up cruft from the manifest file"
                task :manifest, &method( :do_fixup_manifest )


                desc "Remove Bundler-related files"
                task :bundler, &method( :do_fixup_bundler )


                desc "Fix up dependencies file/s"
                task :depsfiles, &method( :do_fixup_legacy_depsfiles )

        end

        task :fixup_debug, &method( :do_fixup_debug )
        task :debug => :fixup_debug
end
anchor
define_tasks()

Define fixup tasks

# File lib/rake/deveiate/fixup.rb, line 43
def define_tasks
        super if defined?( super )

        self.define_hoe_fixup_tasks
end
anchor
do_fixup_bundler( task, * )

Remove any bundler-related files.

# File lib/rake/deveiate/fixup.rb, line 181
def do_fixup_bundler( task, * )
        BUNDLER_FILES.each do |file|
                next unless file.exist?
                self.trace "Removing bundler file %s..." % [ file ]
                self.hg.rm( file, force: true )
        end
end
anchor
do_fixup_debug( task, args )

Task function – output debugging for fixup tasks.

# File lib/rake/deveiate/fixup.rb, line 89
def do_fixup_debug( task, args )
        fixups = []

        fixups << "De-hoeify the Rakefile" if self.rakefile_needs_hoe_fixup?
        fixups << "Remove cruft from the manifest" if self.manifest_needs_fixup?
        fixups << "Remove bundler files" if self.bundler_files_present?
        fixups << "Convert legacy dependency files" if self.legacy_deps_files_present?

        self.prompt.say( "Fixups available:", color: :bright_green )

        if fixups.empty?
                self.prompt.say( "None; project looks clean." )
        else
                fixups.each do |desc|
                        self.prompt.say "[ ] %s" % [ desc ]
                end
        end

        self.prompt.say( "\n" )
end
anchor
do_fixup_legacy_depsfiles( task, * )

Convert legacy dependency files to the newer form.

# File lib/rake/deveiate/fixup.rb, line 191
def do_fixup_legacy_depsfiles( task, * )
        unless self.legacy_deps_files_present?
                self.trace "No legacy dependency files; skipping"
                return
        end

        new_depsfile = Rake::DevEiate::GEMDEPS_FILE

        LEGACY_DEPSFILES.each do |depsfile|
                next unless depsfile.readable?

                if new_depsfile.exist?
                        self.hg.rm( depsfile )
                else
                        depnames = depsfile.each_line.map do |line|
                                line.split( /\s+/, 2 ).first
                        end

                        raise "Failed to read dependencies from %s!" % [ depsfile ] if depnames.empty?

                        if self.hg.tracked?( depsfile )
                                self.trace "Recording move of %s to %s" % [ depsfile, new_depsfile ]
                                self.hg.mv( depsfile, new_depsfile )
                        else
                                depsfile.rename( new_depsfile )
                        end

                        newest_deps = self.find_latest_versions( *depnames ).
                                reject {|tuple| tuple.name.include?('hoe') }
                        dev_deps = self.find_latest_versions( *DEV_GEMDEPS )

                        self.write_replacement_file( new_depsfile, encoding: 'utf-8' ) do |fh|
                                fh.puts "source 'https://rubygems.org/'"
                                fh.puts

                                newest_deps.each do |dep|
                                        fh.puts "gem '%s', '%s'" %
                                                [ dep.name, dep.version.approximate_recommendation ]
                                end

                                fh.puts
                                fh.puts "group :development do"
                                dev_deps.each do |dep|
                                        fh.puts "\tgem '%s', '%s'" %
                                                [ dep.name, dep.version.approximate_recommendation ]
                                end
                                fh.puts "end"
                        end
                end
        end
end
anchor
do_fixup_manifest( task, * )

Clean up cruft from the manifest file.

# File lib/rake/deveiate/fixup.rb, line 164
def do_fixup_manifest( task, * )
        unless self.manifest_needs_fixup?
                self.trace "Manifest is clean; skipping"
                return
        end

        self.write_replacement_file( self.manifest_file, encoding: 'utf-8' ) do |fh|
                self.trace "Removing cruft from the manifest"
                self.manifest_file.each_line do |line|
                        next if line.match?( MANIFEST_CRUFT_LINE )
                        fh.puts( line )
                end
        end
end
anchor
do_fixup_rakefile( task, * )

Replace the current Rakefile with a generated one of it is a Hoe-based one.

# File lib/rake/deveiate/fixup.rb, line 139
def do_fixup_rakefile( task, * )
        unless self.rakefile_needs_hoe_fixup?
                self.trace "Not a hoe-based Rakefile; skipping"
                return
        end

        original = self.rakefile.read

        self.write_replacement_file( self.rakefile, encoding: 'utf-8' ) do |fh|

                self.trace "Re-generating Rakefile from a template"
                template = Rake::DevEiate::Generate::RAKEFILE_TEMPLATE
                boilerplate = self.load_and_render_template( template, 'Rakefile' )
                fh.print( boilerplate )

                self.trace "Appending the old Rakefile contents in an END section"
                fh.puts
                fh.puts "__END__"
                fh.puts
                fh.print( original )
        end
end
anchor
find_latest_versions( *gemnames )

Find the latest version for the specified gemnames and return them as Gem::Specifiations

# File lib/rake/deveiate/fixup.rb, line 245
def find_latest_versions( *gemnames )
        pattern = /\A#{Regexp.union(gemnames)}\Z/
        fetcher = Gem::SpecFetcher.fetcher
        return fetcher.
                detect( :latest ) {|tuple| pattern =~ tuple.name && tuple.platform == 'ruby' }.
                transpose.first
end
anchor
legacy_deps_files_present?()

Return true if there are legacy dependency files in the project

# File lib/rake/deveiate/fixup.rb, line 133
def legacy_deps_files_present?
        return LEGACY_DEPSFILES.any?( &:exist? )
end
anchor
manifest_needs_fixup?()

Returns true if the manifest file has crufty lines in it.

# File lib/rake/deveiate/fixup.rb, line 120
def manifest_needs_fixup?
        return false unless self.manifest_file.exist?
        return self.manifest_file.each_line.any?( MANIFEST_CRUFT_LINE )
end
anchor
rakefile_needs_hoe_fixup?()

Return true if the Rakefile in the current project directory needs to be cleaned up.

# File lib/rake/deveiate/fixup.rb, line 113
def rakefile_needs_hoe_fixup?
        return false unless self.rakefile.exist? && !self.rakefile.zero?
        return self.rakefile.read.split( /^__END__/m, 2 ).first.match?( /hoe/i )
end