Module: Rake::DevEiate::Fixup
- Extended by:
- Rake::DSL
- Defined in:
- lib/rake/deveiate/fixup.rb
Overview
Fixup and conversion tasks
Constant Summary collapse
- MANIFEST_CRUFT_LINE =
Pattern for matching lines in the Manifest that shouldn’t be there
%r{ ^(?: # Match whole lines changelog )$ }xim- BUNDLER_FILES =
Pathnames of Bundler-related files
[ Rake::DevEiate::PROJECT_DIR + 'Gemfile', Rake::DevEiate::PROJECT_DIR + 'Gemfile.lock', Rake::DevEiate::PROJECT_DIR + 'Gemfile.devel', Rake::DevEiate::PROJECT_DIR + 'Gemfile.devel.lock', ]
- LEGACY_DEPSFILES =
Pathnames of legacy dependency files
[ Rake::DevEiate::PROJECT_DIR + '.gems', Rake::DevEiate::PROJECT_DIR + '.rvm.gems', ]
- DEV_GEMDEPS =
Gems to add to the ‘development’ group of the deps file
%w[ rake-deveiate rdoc-generator-fivefish ]
Instance Method Summary collapse
-
#bundler_files_present? ⇒ Boolean
Return
trueif there are Bundler-related files in the project. -
#define_hoe_fixup_tasks ⇒ Object
Set up tasks that check for poor whitespace discipline.
-
#define_tasks ⇒ Object
Define fixup tasks.
-
#do_fixup_bundler(task) ⇒ Object
Remove any bundler-related files.
-
#do_fixup_debug(task, args) ⇒ Object
Task function – output debugging for fixup tasks.
-
#do_fixup_legacy_depsfiles(task) ⇒ Object
Convert legacy dependency files to the newer form.
-
#do_fixup_manifest(task) ⇒ Object
Clean up cruft from the manifest file.
-
#do_fixup_rakefile(task) ⇒ Object
Replace the current Rakefile with a generated one of it is a Hoe-based one.
-
#find_latest_versions(*gemnames) ⇒ Object
Find the latest version for the specified
gemnamesand return them as Gem::Specifiations. -
#legacy_deps_files_present? ⇒ Boolean
Return
trueif there are legacy dependency files in the project. -
#manifest_needs_fixup? ⇒ Boolean
Returns
trueif the manifest file has crufty lines in it. -
#rakefile_needs_hoe_fixup? ⇒ Boolean
Return
trueif the Rakefile in the current project directory needs to be cleaned up.
Instance Method Details
#bundler_files_present? ⇒ Boolean
Return true if there are Bundler-related files in the project.
128 129 130 |
# File 'lib/rake/deveiate/fixup.rb', line 128 def bundler_files_present? return BUNDLER_FILES.any?( &:exist? ) end |
#define_hoe_fixup_tasks ⇒ Object
Set up tasks that check for poor whitespace discipline
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rake/deveiate/fixup.rb', line 52 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 |
#define_tasks ⇒ Object
Define fixup tasks
44 45 46 47 48 |
# File 'lib/rake/deveiate/fixup.rb', line 44 def define_tasks super if defined?( super ) self.define_hoe_fixup_tasks end |
#do_fixup_bundler(task) ⇒ Object
Remove any bundler-related files.
182 183 184 185 186 187 188 |
# File 'lib/rake/deveiate/fixup.rb', line 182 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 |
#do_fixup_debug(task, args) ⇒ Object
Task function – output debugging for fixup tasks.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rake/deveiate/fixup.rb', line 90 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 |
#do_fixup_legacy_depsfiles(task) ⇒ Object
Convert legacy dependency files to the newer form.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/rake/deveiate/fixup.rb', line 192 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 |
#do_fixup_manifest(task) ⇒ Object
Clean up cruft from the manifest file.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rake/deveiate/fixup.rb', line 165 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 |
#do_fixup_rakefile(task) ⇒ Object
Replace the current Rakefile with a generated one of it is a Hoe-based one.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rake/deveiate/fixup.rb', line 140 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 |
#find_latest_versions(*gemnames) ⇒ Object
Find the latest version for the specified gemnames and return them as Gem::Specifiations
246 247 248 249 250 251 252 |
# File 'lib/rake/deveiate/fixup.rb', line 246 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 |
#legacy_deps_files_present? ⇒ Boolean
Return true if there are legacy dependency files in the project
134 135 136 |
# File 'lib/rake/deveiate/fixup.rb', line 134 def legacy_deps_files_present? return LEGACY_DEPSFILES.any?( &:exist? ) end |
#manifest_needs_fixup? ⇒ Boolean
Returns true if the manifest file has crufty lines in it.
121 122 123 124 |
# File 'lib/rake/deveiate/fixup.rb', line 121 def manifest_needs_fixup? return false unless self.manifest_file.exist? return self.manifest_file.each_line.any?( MANIFEST_CRUFT_LINE ) end |
#rakefile_needs_hoe_fixup? ⇒ Boolean
Return true if the Rakefile in the current project directory needs to be cleaned up.
114 115 116 117 |
# File 'lib/rake/deveiate/fixup.rb', line 114 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 |