Class: Rake::DevEiate
- Inherits:
-
TaskLib
- Object
- TaskLib
- Rake::DevEiate
- 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
-
#allowed_push_host ⇒ Object
The gemserver to push gems to.
-
#authors ⇒ Object
The gem’s authors in the form of strings in the format: ‘Name <email>`.
-
#cert_files ⇒ Object
The public cetificates that can be used to verify signed gems.
-
#default_manifest ⇒ Object
The Rake::FileList that’s used in lieu of the manifest file if it isn’t present.
-
#dependencies ⇒ Object
The Gem::RequestSet that describes the gem’s dependencies.
-
#description ⇒ Object
The descriotion of the gem.
-
#executables ⇒ Object
readonly
The Array of project files that are in the bin/ directory and are executable.
-
#extensions ⇒ Object
readonly
A FileMap of the paths to this project’s extension config scripts.
-
#gem_push_key ⇒ Object
An alternative key to use for pushing gems (private gemserver).
-
#homepage ⇒ Object
The URI of the project’s homepage as a String.
-
#licenses ⇒ Object
The licenses the project is distributed under; usual practice is to list the SPDX name: spdx.org/licenses.
-
#name ⇒ Object
readonly
The name of the gem the task will build.
-
#options ⇒ Object
readonly
The options Hash the task lib was created with.
-
#project_files ⇒ Object
The files which should be distributed with the project as a Rake::FileList.
-
#publish_to ⇒ Object
The rsync-compatible target to publish documentation to.
-
#rdoc_files ⇒ Object
The files which should be used to generate documentation as a Rake::FileList.
-
#rdoc_generator ⇒ Object
The name of the RDoc generator to use (assumes any necessary dependencies are installed).
-
#readme ⇒ Object
The README of the project as an RDoc::Markup::Document.
-
#release_branch ⇒ Object
The name of the branch to release from.
-
#release_tag_prefix ⇒ Object
The prefix to use for version tags.
-
#required_ruby_version ⇒ Object
The version of Ruby required by this gem, in Gem version format.
-
#summary ⇒ Object
The summary description of the gem.
-
#title ⇒ Object
The title of the library for things like docs, gemspec, etc.
Class Method Summary collapse
-
.already_setup? ⇒ Boolean
Returns
trueif Rake::DevEiate has already been set up. -
.attr_pathname(name) ⇒ Object
Declare an attribute that should be cast to a Pathname when set.
-
.setup(name, **options, &block) ⇒ Object
Set up common development tasks.
Instance Method Summary collapse
-
#author_names ⇒ Object
Return just the name parts of the library’s authors setting.
-
#define_debug_tasks ⇒ Object
Set up tasks for debugging the task library.
-
#define_default_tasks ⇒ Object
Set up a simple default task.
-
#define_tasks ⇒ Object
Task-definition hook.
-
#extract_authors ⇒ Object
Extract authors in the form ‘Firstname Lastname <email@address>` from the README.
-
#extract_default_title ⇒ Object
Extract the default title from the README if possible, or derive it from the gem name.
-
#extract_description ⇒ Object
Extract a description from the README if possible.
-
#extract_homepage ⇒ Object
Extract the URI of the homepage from the ‘home` item of the first NOTE-type list in the README.
-
#extract_summary ⇒ Object
Extract a summary from the README if possible.
-
#find_dependencies ⇒ Object
Load the gemdeps file if it exists, and return a Gem::RequestSet with the regular dependencies contained in it.
-
#find_executables ⇒ Object
Return an Array of the paths for the executables contained in the project files.
-
#find_history_file ⇒ Object
Find the history file in the list of project files and return it as a Pathname.
-
#find_readme ⇒ Object
Find the README file in the list of project files and return it as a Pathname.
-
#find_version ⇒ Object
Find the file that contains the VERSION constant and return it as a Gem::Version.
-
#generate_dependencies_table ⇒ Object
Generate a TTY::Table from the current dependency list and return it.
-
#generate_project_files_table ⇒ Object
Generate a TTY::Table from the current project files and return it.
-
#get_history_file_versions ⇒ Object
Fetch the list of the versions of releases that have entries in the history file.
-
#has_manifest? ⇒ Boolean
Returns
trueif the manifest file exists and is readable. -
#header_char_for(filename) ⇒ Object
Return the character used to build headings give the filename of the file to be generated.
-
#history_file ⇒ Object
The file that provides high-level change history.
-
#indent(text, spaces = 4) ⇒ Object
Return a copy of the given text prefixed by
spacesnumber of spaces. -
#initialize(name, **options, &block) ⇒ DevEiate
constructor
Create the devEiate tasks for a gem with the given
name. -
#install_dependencies ⇒ Object
Install the gems listed in the gem dependencies file.
-
#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 giventarget_filename. -
#load_task_libraries ⇒ Object
Load the deveiate task libraries.
-
#make_rdoc_filelist ⇒ Object
Make a Rake::FileList of the files that should be used to generate documentation.
-
#manifest_file ⇒ Object
The file to read the list of distribution files from.
-
#output_dependency_debugging ⇒ Object
Output debugging about the project’s dependencies.
-
#output_documentation_debugging ⇒ Object
Output debugging information about documentation.
-
#output_project_files_debugging ⇒ Object
Output debugging info related to the list of project files the build operates on.
-
#parse_readme ⇒ Object
Parse the README into an RDoc::Markup::Document and return it.
-
#pastel ⇒ Object
Fetch the Pastel object, creating it if necessary.
-
#prompt ⇒ Object
Fetch the TTY-Prompt, creating it if necessary.
-
#rakefile ⇒ Object
The project’s Rakefile.
-
#read_manifest ⇒ Object
Read the manifest file if there is one, falling back to a default list if there isn’t a manifest.
-
#read_template(name) ⇒ Object
Read a template with the given
namefrom the data directory and return it as an ERB object. -
#readme_file ⇒ Object
The file that will be the main page of documentation.
-
#release_tag_pattern ⇒ Object
Return a Regexp that matches the project’s convention for versions.
-
#setup(name, **options) ⇒ Object
Post-loading callback.
-
#trace(*args) ⇒ Object
Output
argsto $stderr if tracing is enabled. -
#version ⇒ Object
Return the project version as a Gem::Version, reading it from the #version_from file if it’s not set yet.
-
#version_from ⇒ Object
The pathname of the file to read the version from.
-
#write_replacement_file(filename, **opts) ⇒ Object
Yield an IO to the block open to a file that will replace
filenameif the block returns successfully.
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, **, &block ) @name = validate_gemname( name ) @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. @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_host ⇒ Object
The gemserver to push gems to
295 296 297 |
# File 'lib/rake/deveiate.rb', line 295 def allowed_push_host @allowed_push_host end |
#authors ⇒ Object
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 end |
#cert_files ⇒ Object
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_manifest ⇒ Object
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 |
#dependencies ⇒ Object
The Gem::RequestSet that describes the gem’s dependencies
287 288 289 |
# File 'lib/rake/deveiate.rb', line 287 def dependencies @dependencies end |
#description ⇒ Object
The descriotion of the gem
217 218 219 |
# File 'lib/rake/deveiate.rb', line 217 def description @description end |
#executables ⇒ Object (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 |
#extensions ⇒ Object (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_key ⇒ Object
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 |
#homepage ⇒ Object
The URI of the project’s homepage as a String
283 284 285 |
# File 'lib/rake/deveiate.rb', line 283 def homepage @homepage end |
#licenses ⇒ Object
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 |
#name ⇒ Object (readonly)
The name of the gem the task will build
209 210 211 |
# File 'lib/rake/deveiate.rb', line 209 def name @name end |
#options ⇒ Object (readonly)
The options Hash the task lib was created with
213 214 215 |
# File 'lib/rake/deveiate.rb', line 213 def @options end |
#project_files ⇒ Object
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_to ⇒ Object
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_files ⇒ Object
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_generator ⇒ Object
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 |
#readme ⇒ Object
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_branch ⇒ Object
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_prefix ⇒ Object
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_version ⇒ Object
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 |
#summary ⇒ Object
The summary description of the gem.
221 222 223 |
# File 'lib/rake/deveiate.rb', line 221 def summary @summary end |
#title ⇒ Object
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.
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, **, &block ) tasklib = self.new( name, **, &block ) tasklib.define_tasks return tasklib end |
Instance Method Details
#author_names ⇒ Object
Return just the name parts of the library’s authors setting.
486 487 488 489 490 |
# File 'lib/rake/deveiate.rb', line 486 def return self..map do || [ /^(.*?) </, 1 ] end end |
#define_debug_tasks ⇒ Object
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_tasks ⇒ Object
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_tasks ⇒ Object
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_authors ⇒ Object
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 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_title ⇒ Object
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_description ⇒ Object
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_homepage ⇒ Object
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_summary ⇒ Object
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_dependencies ⇒ Object
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_executables ⇒ Object
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_file ⇒ Object
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_readme ⇒ Object
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_version ⇒ Object
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_table ⇒ Object
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_table ⇒ Object
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_versions ⇒ Object
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.
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_file ⇒ Object
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_dependencies ⇒ Object
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_libraries ⇒ Object
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. ) end |
#make_rdoc_filelist ⇒ Object
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_file ⇒ Object
The file to read the list of distribution files from
249 |
# File 'lib/rake/deveiate.rb', line 249 attr_pathname :manifest_file |
#output_dependency_debugging ⇒ Object
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_debugging ⇒ Object
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..each do || self.prompt.say( " • " ) self.prompt.say( , 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_debugging ⇒ Object
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_readme ⇒ Object
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 |
#pastel ⇒ Object
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 |
#prompt ⇒ Object
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 |
#rakefile ⇒ Object
The project’s Rakefile
237 |
# File 'lib/rake/deveiate.rb', line 237 attr_pathname :rakefile |
#read_manifest ⇒ Object
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_file ⇒ Object
The file that will be the main page of documentation
241 |
# File 'lib/rake/deveiate.rb', line 241 attr_pathname :readme_file |
#release_tag_pattern ⇒ Object
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, ** ) # 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..trace end |
#version ⇒ Object
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_from ⇒ Object
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 ). 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 ). newfile.rename( path ) path.chown( owner, group ) path.chmod( mode ) end end |