Class: Rake::DevEiate

Inherits:
TaskLib
  • Object
show all
Includes:
TraceOutput
Defined in:
lib/rake/deveiate.rb

Overview

A task library for maintaining an open-source library.

Constant Summary collapse

VERSION_PATTERN =

Pattern for extracting a version constant

/VERSION\s*=\s*(?<quote>['"])(?<version>\d+(\.\d+){2}.*)\k<quote>/
VERSION =

The version of this library

'0.27.0'
DEFAULT_GEMSERVER =

The server to release to by default

'https://rubygems.org/'
DEFAULT_HOMEPAGE =

What to use for the homepage if none is set

'https://example.com/'
DEFAULT_DESCRIPTION =

The description to use if none is set

"A gem of some sort."
DEFAULT_VERSION =

The version to use if one cannot be read from the source

'0.1.0'
DEFAULT_RELEASE_TAG_PREFIX =

The prefix to use for release version tags by default

'v'
PACKAGE_IGNORE_WORDS =

Words in the package/gem name that should not be included in deriving paths, file names, etc.

%w[ruby]
PROJECT_DIR =

Paths

Pathname( '.' )
DOCS_DIR =
PROJECT_DIR + 'docs'
LIB_DIR =
PROJECT_DIR + 'lib'
EXT_DIR =
PROJECT_DIR + 'ext'
SPEC_DIR =
PROJECT_DIR + 'spec'
INT_SPEC_DIR =
PROJECT_DIR + 'integration'
DATA_DIR =
PROJECT_DIR + 'data'
CERTS_DIR =
PROJECT_DIR + 'certs'
PKG_DIR =
PROJECT_DIR + 'pkg'
CHECKSUM_DIR =
PROJECT_DIR + 'checksum'
DEFAULT_MANIFEST_FILE =
PROJECT_DIR + 'Manifest.txt'
DEFAULT_README_FILE =
PROJECT_DIR + 'README.md'
DEFAULT_HISTORY_FILE =
PROJECT_DIR + 'History.md'
DEFAULT_PROJECT_FILES =
Rake::FileList[
	'*.{rdoc,md,txt}',
	'bin/*',
	'lib/**/*.rb',
	'ext/*.[ch]', 'ext/**/*.[ch]',
	'data/**/*',
	'spec/**/*.rb',
]
ENV_SETTING_NAME =

Environment variable overrides for settings

{
	version_from: 'VERSION_FROM',
}
DEFAULT_LICENSE =

The default license for the project in SPDX form: spdx.org/licenses

'BSD-3-Clause'
GEMDEPS_FILE =

The file that contains the project’s dependencies

PROJECT_DIR + 'gem.deps.rb'
DOCUMENTATION_SUFFIXES =

The file suffixes to include in documentation

%w[
	.rb
	.c
	.h
	.md
	.rdoc
	.txt
	.png
	.jpg
	.gif
	.svg
]
DEVEIATE_DATADIR =

The path to the data directory

if ENV['DEVEIATE_DATADIR']
	Pathname( ENV['DEVEIATE_DATADIR'] )
elsif Gem.loaded_specs['rake-deveiate'] &&
      File.directory?( Gem.loaded_specs['rake-deveiate'].datadir )
	Pathname( Gem.loaded_specs['rake-deveiate'].datadir )
else
	Pathname( __FILE__ ).dirname.parent.parent + 'data/rake-deveiate'
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options, &block) ⇒ DevEiate

Create the devEiate tasks for a gem with the given name.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rake/deveiate.rb', line 154

def initialize( name, **options, &block )
	@name                  = validate_gemname( name )
	@options               = options

	@default_manifest      = DEFAULT_PROJECT_FILES.dup

	@rakefile              = PROJECT_DIR + 'Rakefile'
	@manifest_file         = DEFAULT_MANIFEST_FILE.dup
	@project_files         = self.read_manifest
	@executables           = self.find_executables
	@readme_file           = self.find_readme
	@history_file          = self.find_history_file
	@readme                = self.parse_readme
	@rdoc_files            = self.make_rdoc_filelist
	@rdoc_generator        = :sixfish
	@cert_files            = Rake::FileList[ CERTS_DIR + '*.pem' ]
	@licenses              = [ DEFAULT_LICENSE ]
	@version_from          = env( :version_from, as_pathname: true ) ||
		LIB_DIR + "%s.rb" % [ version_file_from(name) ]
	@release_tag_prefix    = DEFAULT_RELEASE_TAG_PREFIX

	@docs_dir              = DOCS_DIR.dup

	@title                 = self.extract_default_title
	@authors               = self.extract_authors
	@homepage              = self.extract_homepage
	@description           = self.extract_description || DEFAULT_DESCRIPTION
	@summary               = nil
	@dependencies          = self.find_dependencies
	@extensions            = Rake::FileList.new

	@version               = nil
	@publish_to            = nil
	@required_ruby_version = nil

	super()

	self.load_task_libraries

	if block
		if block.arity.nonzero?
			block.call( self )
		else
			self.instance_exec( self, &block )
		end
	end
end

Instance Attribute Details

#allowed_push_hostObject

The gemserver to push gems to



295
296
297
# File 'lib/rake/deveiate.rb', line 295

def allowed_push_host
  @allowed_push_host
end

#authorsObject

The gem’s authors in the form of strings in the format: ‘Name <email>`



279
280
281
# File 'lib/rake/deveiate.rb', line 279

def authors
  @authors
end

#cert_filesObject

The public cetificates that can be used to verify signed gems



270
271
272
# File 'lib/rake/deveiate.rb', line 270

def cert_files
  @cert_files
end

#default_manifestObject

The Rake::FileList that’s used in lieu of the manifest file if it isn’t present.



320
321
322
# File 'lib/rake/deveiate.rb', line 320

def default_manifest
  @default_manifest
end

#dependenciesObject

The Gem::RequestSet that describes the gem’s dependencies



287
288
289
# File 'lib/rake/deveiate.rb', line 287

def dependencies
  @dependencies
end

#descriptionObject

The descriotion of the gem



217
218
219
# File 'lib/rake/deveiate.rb', line 217

def description
  @description
end

#executablesObject (readonly)

The Array of project files that are in the bin/ directory and are executable.



257
258
259
# File 'lib/rake/deveiate.rb', line 257

def executables
  @executables
end

#extensionsObject (readonly)

A FileMap of the paths to this project’s extension config scripts.



291
292
293
# File 'lib/rake/deveiate.rb', line 291

def extensions
  @extensions
end

#gem_push_keyObject

An alternative key to use for pushing gems (private gemserver)



299
300
301
# File 'lib/rake/deveiate.rb', line 299

def gem_push_key
  @gem_push_key
end

#homepageObject

The URI of the project’s homepage as a String



283
284
285
# File 'lib/rake/deveiate.rb', line 283

def homepage
  @homepage
end

#licensesObject

The licenses the project is distributed under; usual practice is to list the SPDX name: spdx.org/licenses



275
276
277
# File 'lib/rake/deveiate.rb', line 275

def licenses
  @licenses
end

#nameObject (readonly)

The name of the gem the task will build



209
210
211
# File 'lib/rake/deveiate.rb', line 209

def name
  @name
end

#optionsObject (readonly)

The options Hash the task lib was created with



213
214
215
# File 'lib/rake/deveiate.rb', line 213

def options
  @options
end

#project_filesObject

The files which should be distributed with the project as a Rake::FileList



253
254
255
# File 'lib/rake/deveiate.rb', line 253

def project_files
  @project_files
end

#publish_toObject

The rsync-compatible target to publish documentation to.



303
304
305
# File 'lib/rake/deveiate.rb', line 303

def publish_to
  @publish_to
end

#rdoc_filesObject

The files which should be used to generate documentation as a Rake::FileList



261
262
263
# File 'lib/rake/deveiate.rb', line 261

def rdoc_files
  @rdoc_files
end

#rdoc_generatorObject

The name of the RDoc generator to use (assumes any necessary dependencies are installed)



266
267
268
# File 'lib/rake/deveiate.rb', line 266

def rdoc_generator
  @rdoc_generator
end

#readmeObject

The README of the project as an RDoc::Markup::Document



225
226
227
# File 'lib/rake/deveiate.rb', line 225

def readme
  @readme
end

#release_branchObject

The name of the branch to release from



315
316
317
# File 'lib/rake/deveiate.rb', line 315

def release_branch
  @release_branch
end

#release_tag_prefixObject

The prefix to use for version tags



311
312
313
# File 'lib/rake/deveiate.rb', line 311

def release_tag_prefix
  @release_tag_prefix
end

#required_ruby_versionObject

The version of Ruby required by this gem, in Gem version format.



307
308
309
# File 'lib/rake/deveiate.rb', line 307

def required_ruby_version
  @required_ruby_version
end

#summaryObject

The summary description of the gem.



221
222
223
# File 'lib/rake/deveiate.rb', line 221

def summary
  @summary
end

#titleObject

The title of the library for things like docs, gemspec, etc.



229
230
231
# File 'lib/rake/deveiate.rb', line 229

def title
  @title
end

Class Method Details

.already_setup?Boolean

Returns true if Rake::DevEiate has already been set up.

Returns:

  • (Boolean)


148
149
150
# File 'lib/rake/deveiate.rb', line 148

def self::already_setup?
	Rake::Task.task_defined?( 'deveiate' )
end

.attr_pathname(name) ⇒ Object

Declare an attribute that should be cast to a Pathname when set.



131
132
133
134
135
136
# File 'lib/rake/deveiate.rb', line 131

def self::attr_pathname( name ) # :nodoc:
	attr_reader( name )
	define_method( "#{name}=" ) do |new_value|
		instance_variable_set( "@#{name}", Pathname(new_value) )
	end
end

.setup(name, **options, &block) ⇒ Object

Set up common development tasks



140
141
142
143
144
# File 'lib/rake/deveiate.rb', line 140

def self::setup( name, **options, &block )
	tasklib = self.new( name, **options, &block )
	tasklib.define_tasks
	return tasklib
end

Instance Method Details

#author_namesObject

Return just the name parts of the library’s authors setting.



486
487
488
489
490
# File 'lib/rake/deveiate.rb', line 486

def author_names
	return self.authors.map do |author|
		author[ /^(.*?) </, 1 ]
	end
end

#define_debug_tasksObject

Set up tasks for debugging the task library.



414
415
416
417
418
419
420
421
422
# File 'lib/rake/deveiate.rb', line 414

def define_debug_tasks
	task( :base_debug ) do
		self.output_documentation_debugging
		self.output_project_files_debugging
		self.output_dependency_debugging
	end

	task :debug => :base_debug
end

#define_default_tasksObject

Set up a simple default task



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/rake/deveiate.rb', line 366

def define_default_tasks

	# task used to indicate that rake-deveiate has already been setup once; for
	# global rakefiles.
	task :deveiate do
		# no-op
	end

	desc "The task that runs by default"
	task( :default => :spec )

	desc "Check in the current changes"
	task :checkin => [ :precheckin, :check, :test ]
	task :commit => :checkin
	task :ci => :checkin
	task :precheckin

	desc "Sanity-check the project"
	task :check

	desc "Update the history file"
	task :update_history

	desc "Package up and push a release"
	task :release => [ :prerelease, :gem, :release_gem, :postrelease ]
	task :prerelease
	task :release_gem
	task :postrelease

	desc "Run all the project's tests"
	task :test
	task :spec
	task :integration

	desc "Set up the project for development"
	task :setup do
		self.install_dependencies
	end

	desc "Turn on maintainer mode: build with extra warnings and debugging"
	task :maint do
		ENV['MAINTAINER_MODE'] = 'yes'
	end

end

#define_tasksObject

Task-definition hook.



357
358
359
360
361
362
# File 'lib/rake/deveiate.rb', line 357

def define_tasks
	self.define_default_tasks
	self.define_debug_tasks

	super if defined?( super )
end

#extract_authorsObject

Extract authors in the form ‘Firstname Lastname <email@address>` from the README.



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# File 'lib/rake/deveiate.rb', line 494

def extract_authors
	readme = self.readme or return []
	content = readme.parts.grep_v( RDoc::Markup::BlankLine )

	heading, list = content.each_cons( 2 ).find do |heading, list|
		heading.is_a?( RDoc::Markup::Heading ) &&
			heading.text =~ /^(author|maintainer)s?/i &&
			list.is_a?( RDoc::Markup::List )
	end

	unless list
		self.trace "Couldn't find an Author(s) section of the readme."
		return []
	end

	return list.items.map do |item|
		# unparse the name + email
		raw = item.parts.first.text or next
		name, email = raw.split( ' mailto:', 2 )
		if email
			"%s <%s>" % [ name, email ]
		else
			name
		end
	end
end

#extract_default_titleObject

Extract the default title from the README if possible, or derive it from the gem name.



461
462
463
464
465
# File 'lib/rake/deveiate.rb', line 461

def extract_default_title
	return self.name unless self.readme&.table_of_contents&.first
	title = self.readme.table_of_contents.first.text
	title ||= self.name
end

#extract_descriptionObject

Extract a description from the README if possible. Returns nil if not.



475
476
477
478
479
480
481
482
# File 'lib/rake/deveiate.rb', line 475

def extract_description
	parts = self.readme&.parts or return nil
	desc_para = parts.find {|part| part.is_a?(RDoc::Markup::Paragraph) }&.text or return nil
	formatter = RDoc::Markup::ToHtml.new( RDoc::Options.new )
	html = formatter.convert( desc_para )

	return html.gsub( /<.*?>/, '' ).strip
end

#extract_homepageObject

Extract the URI of the homepage from the ‘home` item of the first NOTE-type list in the README. Returns nil if no such URI could be found.



524
525
526
527
528
529
530
531
532
533
# File 'lib/rake/deveiate.rb', line 524

def extract_homepage
	return fail_extraction( :homepage, "no README" ) unless self.readme

	list = self.readme.parts.find {|part| RDoc::Markup::List === part && part.type == :NOTE } or
		return fail_extraction(:homepage, "No NOTE list")
	item = list.items.find {|item| item.label.include?('home') } or
		return fail_extraction(:homepage, "No `home` item")

	return item.parts.first.text
end

#extract_summaryObject

Extract a summary from the README if possible. Returns nil if not.



469
470
471
# File 'lib/rake/deveiate.rb', line 469

def extract_summary
	return self.description.split( /(?<=\.)\s+/ ).first&.gsub( /\n/, ' ' )
end

#find_dependenciesObject

Load the gemdeps file if it exists, and return a Gem::RequestSet with the regular dependencies contained in it.



700
701
702
703
704
705
706
707
708
709
710
# File 'lib/rake/deveiate.rb', line 700

def find_dependencies
	unless GEMDEPS_FILE.readable?
		self.prompt.warn "Deps file (%s) is missing or unreadable, assuming no dependencies." %
			[ GEMDEPS_FILE ]
		return []
	end

	finder = Rake::DevEiate::GemDepFinder.new( GEMDEPS_FILE )
	finder.load
	return finder.dependencies
end

#find_executablesObject

Return an Array of the paths for the executables contained in the project files.



537
538
539
540
541
542
# File 'lib/rake/deveiate.rb', line 537

def find_executables
	paths = self.project_files.find_all do |path|
		path.start_with?( 'bin/' )
	end
	return paths.map {|path| path[%r{^bin/(.*)}, 1] }
end

#find_history_fileObject

Find the history file in the list of project files and return it as a Pathname.



637
638
639
640
641
642
643
644
645
# File 'lib/rake/deveiate.rb', line 637

def find_history_file
	file = self.project_files.find {|file| file =~ /^History\.(md|rdoc)$/ }
	if file
		return Pathname( file )
	else
		self.prompt.warn "No History.{md,rdoc} found in the project files."
		return DEFAULT_HISTORY_FILE
	end
end

#find_readmeObject

Find the README file in the list of project files and return it as a Pathname.



624
625
626
627
628
629
630
631
632
# File 'lib/rake/deveiate.rb', line 624

def find_readme
	file = self.project_files.find {|file| file =~ /^README\.(md|rdoc)$/ }
	if file
		return Pathname( file )
	else
		self.prompt.warn "No README found in the project files."
		return DEFAULT_README_FILE
	end
end

#find_versionObject

Find the file that contains the VERSION constant and return it as a Gem::Version.



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/rake/deveiate.rb', line 554

def find_version
	version_file = self.version_from

	unless version_file.readable?
		self.prompt.warn "Version could not be read from %s" % [ version_file ]
		return nil
	end

	version_line = version_file.readlines.find {|l| l =~ VERSION_PATTERN } or
		abort "Can't read the VERSION from #{version_file}!"
	version = version_line[ VERSION_PATTERN, :version ] or
		abort "Couldn't find a semantic version in %p" % [ version_line ]

	return Gem::Version.new( version )
end

#generate_dependencies_tableObject

Generate a TTY::Table from the current dependency list and return it.



672
673
674
675
676
677
678
679
680
# File 'lib/rake/deveiate.rb', line 672

def generate_dependencies_table
	table = TTY::Table.new( header: ['Gem', 'Version', 'Type'] )

	self.dependencies.each do |dep|
		table << [ dep.name, dep.requirement.to_s, dep.type ]
	end

	return table
end

#generate_project_files_tableObject

Generate a TTY::Table from the current project files and return it.



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/rake/deveiate.rb', line 649

def generate_project_files_table
	columns = [
		self.project_files.sort,
		self.rdoc_files.sort
	]

	max_length = columns.map( &:length ).max
	columns.each do |col|
		self.trace "Filling out columns %d-%d" % [ col.length, max_length ]
		next if col.length == max_length
		col.fill( '', col.length .. max_length - 1 )
	end

	table = TTY::Table.new(
		header: ['Project', 'Documentation'],
		rows: columns.transpose,
	)

	return table
end

#get_history_file_versionsObject

Fetch the list of the versions of releases that have entries in the history file.



580
581
582
583
584
585
586
# File 'lib/rake/deveiate.rb', line 580

def get_history_file_versions
	tag_pattern = self.release_tag_pattern

	return IO.readlines( self.history_file ).grep( tag_pattern ).map do |line|
		line[ /^(?:h\d\.|#+|=+)\s+(#{tag_pattern})\s+/, 1 ]
	end.compact
end

#has_manifest?Boolean

Returns true if the manifest file exists and is readable.

Returns:

  • (Boolean)


590
591
592
# File 'lib/rake/deveiate.rb', line 590

def has_manifest?
	return self.manifest_file.readable?
end

#header_char_for(filename) ⇒ Object

Return the character used to build headings give the filename of the file to be generated.



722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/rake/deveiate.rb', line 722

def header_char_for( filename )
	case File.extname( filename )
	when '.md' then return '#'
	when '.rdoc' then return '='
	when ''
		if filename == 'Rakefile'
			return '#'
		end
	end

	raise "Don't know what header character is appropriate for %s" % [ filename ]
end

#history_fileObject

The file that provides high-level change history



245
# File 'lib/rake/deveiate.rb', line 245

attr_pathname :history_file

#indent(text, spaces = 4) ⇒ Object

Return a copy of the given text prefixed by spaces number of spaces.



834
835
836
837
# File 'lib/rake/deveiate.rb', line 834

def indent( text, spaces=4 )
	prefix = ' ' * spaces
	return text.gsub( /(?<=\A|\n)/m, prefix )
end

#install_dependenciesObject

Install the gems listed in the gem dependencies file.



714
715
716
717
# File 'lib/rake/deveiate.rb', line 714

def install_dependencies
	self.prompt.say "Installing dependencies"
	ruby '-S', 'gem', 'i', '-Ng'
end

#load_and_render_template(template_path, target_filename) ⇒ Object

Load the template at the specified template_path, and render it with suitable settings for the given target_filename.



749
750
751
752
753
754
755
756
757
# File 'lib/rake/deveiate.rb', line 749

def load_and_render_template( template_path, target_filename )
	template = self.read_template( template_path )
	header_char = self.header_char_for( target_filename )

	return template.result_with_hash(
		header_char: header_char,
		project: self
	)
end

#load_task_librariesObject

Load the deveiate task libraries.



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/rake/deveiate.rb', line 328

def load_task_libraries
	taskdir = Pathname( __FILE__.delete_suffix('.rb') )
	tasklibs = Rake::FileList[ taskdir + '*.rb' ].pathmap( '%-2d/%n' )

	self.trace( "Loading task libs: %p" % [ tasklibs ] )
	tasklibs.each do |lib|
		require( lib )
	end

	self.class.constants.
		map {|c| self.class.const_get(c) }.
		select {|c| c.respond_to?(:instance_methods) }.
		select {|c| c.instance_methods(false).include?(:define_tasks) }.
		each do |mod|
			self.trace "Loading tasks from %p" % [ mod ]
			extend( mod )
		end

	self.setup( self.name, **self.options )
end

#make_rdoc_filelistObject

Make a Rake::FileList of the files that should be used to generate documentation.



611
612
613
614
615
616
617
618
619
# File 'lib/rake/deveiate.rb', line 611

def make_rdoc_filelist
	list = self.project_files.dup

	list.exclude do |fn|
		fn =~ %r:^(spec|data)/: || !fn.end_with?( *DOCUMENTATION_SUFFIXES )
	end

	return list
end

#manifest_fileObject

The file to read the list of distribution files from



249
# File 'lib/rake/deveiate.rb', line 249

attr_pathname :manifest_file

#output_dependency_debuggingObject

Output debugging about the project’s dependencies.



821
822
823
824
825
826
827
828
829
830
# File 'lib/rake/deveiate.rb', line 821

def output_dependency_debugging
	self.prompt.say( "Dependencies", color: :bright_green )
	table = self.generate_dependencies_table
	if table.empty?
		self.prompt.warn( "None." )
	else
		self.prompt.say( table.render(:unicode, padding: [0,1]) )
	end
	self.prompt.say( "\n" )
end

#output_documentation_debuggingObject

Output debugging information about documentation.



781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# File 'lib/rake/deveiate.rb', line 781

def output_documentation_debugging
	summary = self.extract_summary
	description = self.extract_description
	homepage = self.extract_homepage || DEFAULT_HOMEPAGE

	self.prompt.say( "Documentation", color: :bright_green )
	self.prompt.say( "Authors:" )
	self.authors.each do |author|
		self.prompt.say( "" )
		self.prompt.say( author, color: :bold )
	end
	self.prompt.say( "Summary: " )
	self.prompt.say( summary, color: :bold )
	self.prompt.say( "Description:" )
	self.prompt.say( "   " + description, color: :bold )
	self.prompt.say( "Homepage:" )
	self.prompt.say( "   " + homepage, color: :bold )
	self.prompt.say( "\n" )
end

#output_project_files_debuggingObject

Output debugging info related to the list of project files the build operates on.



804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/rake/deveiate.rb', line 804

def output_project_files_debugging
	self.prompt.say( "Project files:", color: :bright_green )
	table = self.generate_project_files_table
	if table.empty?
		self.prompt.warn( "None." )
	else
		self.prompt.say( table.render(:unicode, padding: [0,1]) )
	end
	self.prompt.say( "\n" )

	self.prompt.say( "Version from:" )
	self.prompt.say( "  " + self.version_from.to_s, color: :bold )
	self.prompt.say( "\n" )
end

#parse_readmeObject

Parse the README into an RDoc::Markup::Document and return it



684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/rake/deveiate.rb', line 684

def parse_readme
	return nil unless self.readme_file.readable?

	case self.readme_file.extname
	when '.md'
		return RDoc::Markdown.parse( self.readme_file.read )
	when '.rdoc'
		return RDoc::Markup.parse( self.readme_file.read )
	else
		raise "Can't parse %s: unhandled format %p" % [ self.readme_file, README_FILE.extname ]
	end
end

#pastelObject

Fetch the Pastel object, creating it if necessary.



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/rake/deveiate.rb', line 436

def pastel
	return @pastel ||= begin
		pastel = Pastel.new( enabled: $stdout.tty? )
		pastel.alias_color( :headline, :bold, :white, :on_black )
		pastel.alias_color( :success, :bold, :green )
		pastel.alias_color( :error, :bold, :red )
		pastel.alias_color( :warning, :yellow )
		pastel.alias_color( :added, :green )
		pastel.alias_color( :removed, :red )
		pastel.alias_color( :prompt, :cyan )
		pastel.alias_color( :even_row, :bold )
		pastel.alias_color( :odd_row, :reset )
		pastel
	end
end

#promptObject

Fetch the TTY-Prompt, creating it if necessary.



430
431
432
# File 'lib/rake/deveiate.rb', line 430

def prompt
	return @prompt ||= TTY::Prompt.new( output: $stderr )
end

#rakefileObject

The project’s Rakefile



237
# File 'lib/rake/deveiate.rb', line 237

attr_pathname :rakefile

#read_manifestObject

Read the manifest file if there is one, falling back to a default list if there isn’t a manifest.



597
598
599
600
601
602
603
604
605
606
# File 'lib/rake/deveiate.rb', line 597

def read_manifest
	if self.has_manifest?
		entries = self.manifest_file.readlines.map( &:chomp )
		return Rake::FileList[ *entries ]
	else
		self.prompt.warn "No manifest (%s): falling back to a default list" %
			[ self.manifest_file ]
		return self.default_manifest
	end
end

#read_template(name) ⇒ Object

Read a template with the given name from the data directory and return it as an ERB object.



738
739
740
741
742
743
744
# File 'lib/rake/deveiate.rb', line 738

def read_template( name )
	name = "%s.erb" % [ name ] unless name.to_s.end_with?( '.erb' )
	template_path = DEVEIATE_DATADIR + name
	template_src = template_path.read( encoding: 'utf-8' )

	return ERB.new( template_src, trim_mode: '-' )
end

#readme_fileObject

The file that will be the main page of documentation



241
# File 'lib/rake/deveiate.rb', line 241

attr_pathname :readme_file

#release_tag_patternObject

Return a Regexp that matches the project’s convention for versions.



572
573
574
575
# File 'lib/rake/deveiate.rb', line 572

def release_tag_pattern
	prefix = self.release_tag_prefix
	return /#{prefix}\d+(\.\d+)+/
end

#setup(name, **options) ⇒ Object

Post-loading callback.



351
352
353
# File 'lib/rake/deveiate.rb', line 351

def setup( name, **options )
	# No-op
end

#trace(*args) ⇒ Object

Output args to $stderr if tracing is enabled.



454
455
456
# File 'lib/rake/deveiate.rb', line 454

def trace( *args )
	Rake.application.trace( *args ) if Rake.application.options.trace
end

#versionObject

Return the project version as a Gem::Version, reading it from the #version_from file if it’s not set yet.



547
548
549
# File 'lib/rake/deveiate.rb', line 547

def version
	return @version ||= self.find_version
end

#version_fromObject

The pathname of the file to read the version from



233
# File 'lib/rake/deveiate.rb', line 233

attr_pathname :version_from

#write_replacement_file(filename, **opts) ⇒ Object

Yield an IO to the block open to a file that will replace filename if the block returns successfully.



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# File 'lib/rake/deveiate.rb', line 762

def write_replacement_file( filename, **opts )
	path = Pathname( filename ).expand_path
	mode = path.stat.mode
	owner = path.stat.uid
	group = path.stat.gid

	tmpfile = Tempfile.create( path.basename.to_s, **opts ) do |fh|
		yield( fh )

		newfile = Pathname( fh.path ).expand_path
		newfile.rename( path )

		path.chown( owner, group )
		path.chmod( mode )
	end
end