Class: GemHadar
- Inherits:
-
Object
- Object
- GemHadar
- Extended by:
- DSLKit::DSLAccessor
- Includes:
- Config, Editor, OllamaSupport, PromptTemplate, Utils, Warn, Rake::DSL, RbConfig, Term::ANSIColor, Tins::SecureWrite
- Defined in:
- lib/gem_hadar.rb,
lib/gem_hadar.rb,
lib/gem_hadar/warn.rb,
lib/gem_hadar/version.rb,
lib/gem_hadar/simplecov.rb,
lib/gem_hadar/rvm_config.rb,
lib/gem_hadar/changelog_generator.rb
Overview
The GemHadar class serves as the primary configuration and task management framework for Ruby gem projects. It provides a DSL for defining gem metadata, dependencies, and Rake tasks, while also offering integration with various tools such as GitHub, SimpleCov, YARD, and Ollama for automating common development workflows.
Defined Under Namespace
Modules: Editor, GitHub, OllamaSupport, PromptTemplate, SimpleCov, Utils, Warn Classes: ChangelogConfig, ChangelogGenerator, RvmConfig, Setup, TemplateCompiler, VersionSpec
Constant Summary collapse
- VERSION =
GemHadar version
'2.16.0'- VERSION_ARRAY =
:nodoc:
VERSION.split('.').map(&:to_i)
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Instance Method Summary collapse
-
#assert_valid_link(name, orig_url) ⇒ String
The assert_valid_link method verifies that the provided URL is valid by checking if it returns an HTTP OK status after following redirects, unless project is still ‘developing`.
-
#bindir ⇒ String?
The bindir attribute accessor for configuring the gem’s binary directory.
-
#build_task ⇒ Object
The build_task method defines a Rake task that orchestrates the complete build process for packaging the gem.
-
#build_task_dependencies ⇒ Array<Symbol, String>
The build_task_dependencies method manages the list of dependencies for the build task.
-
#changelog(&block) ⇒ GemHadar::ChangelogConfig
The changelog method configures or retrieves the changelog settings for the gem project.
-
#changes_task ⇒ Object
The changes_task method defines namespaced Rake tasks for generating changelogs.
-
#clean(*args) ⇒ FileList?
The clean method manages the CLEAN file list for Rake tasks.
-
#clobber(*args) ⇒ FileList?
The clobber method manages the CLOBBER file list for Rake tasks.
-
#compile_task ⇒ Object
The compile_task method sets up a Rake task to compile project extensions.
-
#config_task ⇒ Object
The config_task method creates a Rake task that displays the current GemHadar configuration.
-
#create_all_tasks ⇒ GemHadar
The create_all_tasks method sets up and registers all the Rake tasks for the gem project.
-
#create_git_release_body ⇒ String
The create_git_release_body method generates a changelog for a GitHub release by analyzing the git diff between the previous version and the current HEAD.
-
#create_github_workflow_templates ⇒ Object
The create_github_workflow_templates method compiles GitHub Actions workflow templates from ERB files into actual YAML workflow files in the project’s .github/workflows directory.
-
#default_task ⇒ Object
The default_task method defines the default Rake task for the gem project.
-
#default_task_dependencies ⇒ Array<Symbol, String>
The default_task_dependencies method manages the list of dependencies for the default Rake task.
-
#dependency(*args) ⇒ Object
The dependency method adds a new runtime dependency to the gem.
-
#description ⇒ String
The description attribute accessor for configuring the gem’s description.
-
#determine_version_range ⇒ Array(String, String)
Determine the start and end versions for diff comparison.
-
#developing ⇒ Boolean
The developing attribute accessor for configuring development mode.
-
#development_dependency(*args) ⇒ Object
The development_dependency method adds a new development-time dependency to the gem.
-
#doc_code_files ⇒ FileList
The doc_code_files method manages the list of code files to be included in documentation generation.
-
#doc_files ⇒ FileList
The doc_files attribute accessor for configuring additional documentation files.
-
#email ⇒ String
The email attribute accessor for configuring the gem’s author email.
-
#executables ⇒ Set<String>
The executables attribute accessor for configuring the gem’s executable files.
-
#extensions ⇒ FileList
The extensions attribute accessor for configuring project extensions.
-
#files ⇒ Array<String>
The files attribute accessor for configuring the list of files included in the gem package.
-
#gem_files ⇒ Array<String>
The gem_files method returns an array of files that are included in the gem package.
-
#gem_hadar_update_task ⇒ Object
The gem_hadar_update_task method defines a Rake task that updates the gem_hadar dependency version in the gemspec file.
-
#gem_push_task ⇒ Object
The gem_push_task method defines a Rake task for pushing the generated gem file to RubyGems.
-
#gems_install_task(&block) ⇒ Object
The gems_install_task method defines a Rake task for installing all gem dependencies specified in the Gemfile.
-
#gemspec ⇒ Gem::Specification
The gemspec method creates and returns a new Gem::Specification object that defines the metadata and dependencies for the gem package.
-
#gemspec_task ⇒ Object
The gemspec_task method defines a Rake task that generates and writes a gemspec file for the project.
-
#git_remote ⇒ Object
The git_remote method retrieves the primary Git remote name configured for the project.
-
#git_remotes ⇒ Array<String>
The git_remotes method retrieves the list of remote repositories configured for the current Git project.
-
#git_remotes_task ⇒ Object
The git_remotes_task method defines a Rake task that displays all Git remote repositories configured for the project.
-
#github_release_task ⇒ Object
The github_release_task method defines a Rake task that creates a GitHub release for the current version.
-
#github_remote_url ⇒ URI?
The github_remote_url method retrieves and parses the GitHub remote URL from the local Git configuration.
-
#github_workflows ⇒ Hash
The github_workflows attribute accessor for configuring GitHub Actions workflows.
-
#github_workflows_task ⇒ Object
The github_workflows_task method sets up Rake tasks for generating GitHub Actions workflow files from ERB templates.
-
#github_workflows_variables ⇒ Hash
The github_workflows_variables method retrieves the cached variables used for GitHub Actions workflow template compilation.
-
#has_to_be_set(name) ⇒ Object
The has_to_be_set method raises an error if a required gem configuration attribute is not set.
-
#homepage ⇒ String
The homepage attribute accessor for configuring the gem’s homepage URL.
-
#ignore(*args) ⇒ Set<String>?
The ignore method manages the list of files to be ignored by the gem.
-
#ignore_files ⇒ Set<String>
The ignore_files attribute accessor for configuring files to be ignored by the gem.
-
#initialize {|gem_hadar| ... } ⇒ GemHadar
constructor
The initialize method sets up a new GemHadar instance and configures it using the provided block.
-
#install_library(&block) ⇒ Object
The install_library method sets up a Rake task for installing the library or executable into site_ruby directories.
-
#install_library_task ⇒ Object
The install_library_task method executes the installed library task block if it has been defined.
-
#licenses ⇒ Set<String>
The licenses attribute accessor for configuring the gem’s license information.
-
#make ⇒ String?
The make method retrieves the make command to be used for building extensions.
-
#master_prepare_task ⇒ Object
The master_prepare_task method defines a Rake task that sets up a remote Git repository for the project.
-
#master_push_task ⇒ Object
The master_push_task method defines Rake tasks for pushing the master branch to configured Git remotes.
-
#modified_task ⇒ Object
The modified_task method defines a Rake task that checks for uncommitted changes in the Git repository.
-
#module_type ⇒ Symbol
The module_type attribute accessor for configuring the type of Ruby construct to generate for version code.
-
#name ⇒ String
The name attribute accessor for configuring the gem’s name.
-
#name_version ⇒ String
The name_version method computes and returns the combined gem name and version string.
-
#ollama_model_default ⇒ String
The ollama_model_default method returns the default name of the Ollama AI model to be used for generating responses when no custom model is specified.
-
#package_ignore(*args) ⇒ Set<String>?
The package_ignore method manages the list of files to be ignored during gem packaging.
-
#package_ignore_files ⇒ Set<String>
The package_ignore_files attribute accessor for configuring files to be ignored during gem packaging.
-
#package_task ⇒ Object
The package_task method sets up a Rake task for packaging the gem.
-
#path_module ⇒ String
The path_module attribute accessor for configuring the Ruby module name.
-
#path_name ⇒ String
The path_name attribute accessor for configuring the gem’s path name.
-
#post_install_message ⇒ String?
The post_install_message attribute accessor for configuring a message to display after gem installation.
-
#push_task ⇒ Object
The push_task method defines a Rake task that orchestrates the complete process of pushing changes and artifacts to remote repositories and package managers.
-
#push_task_dependencies ⇒ Array<Symbol, String>
The push_task_dependencies method manages the list of dependencies for the push task.
-
#rcov_task ⇒ Object
The rcov_task method sets up a Rake task for executing code coverage tests using RCov.
-
#readme ⇒ String?
The readme attribute accessor for configuring the gem’s README file.
-
#release_task ⇒ Object
The release_task method defines a Rake task that orchestrates the complete release process for the gem.
-
#require_path(path = nil) ⇒ String
The require_path method manages the gem’s require path configuration.
-
#require_paths ⇒ Set<String>
The require_paths attribute accessor for configuring the gem’s require paths.
-
#required_ruby_version ⇒ String?
The required_ruby_version attribute accessor for configuring the minimum Ruby version requirement.
-
#rvm(&block) ⇒ GemHadar::RvmConfig
The rvm method configures RVM (Ruby Version Manager) settings for the gem project.
-
#rvm_task ⇒ Object
The rvm_task method creates a .rvmrc file that configures RVM to use the specified Ruby version and gemset for the project.
-
#spec_dir ⇒ String?
The spec_dir attribute accessor for configuring the RSpec specification directory.
-
#spec_pattern ⇒ String
The spec_pattern method configures the pattern used to locate RSpec test files.
-
#spec_task ⇒ Object
The spec_task method sets up a Rake task for executing RSpec tests.
-
#summary ⇒ String
The summary attribute accessor for configuring the gem’s summary.
-
#test_dir ⇒ String?
The test_dir attribute accessor for configuring the test directory.
-
#test_files ⇒ FileList
The test_files attribute accessor for configuring the list of test files to be included in the gem package.
-
#test_task ⇒ Object
The test_task method sets up a Rake task for executing the project’s test suite.
-
#title ⇒ String?
The title attribute accessor for configuring the gem’s documentation title.
-
#version ⇒ String
The version attribute accessor for configuring the gem’s version.
-
#version_bump_task ⇒ Object
The version_bump_task method defines Rake tasks for incrementing the gem’s version number.
-
#version_bump_to(type) ⇒ Object
Increases the specified part of the version number and writes it back to the VERSION file.
-
#version_diff_task ⇒ Object
The version_diff_task method defines Rake tasks for listing and displaying git version differences.
-
#version_epilogue ⇒ String?
The version_epilogue attribute accessor for configuring additional content to be appended to the version file.
-
#version_log_diff(to_version: 'HEAD', from_version: nil) ⇒ String
The version_log_diff method generates a git log output containing patch differences between two specified versions.
-
#version_push_task ⇒ Object
The version_push_task method defines Rake tasks for pushing version tags to Git remotes.
-
#version_show_task ⇒ Object
The version_show_task method defines a Rake task that displays the current version of the gem.
-
#version_tag_list ⇒ Array<GemHadar::VersionSpec>
The version_tag_list method retrieves and processes semantic version tags from the Git repository.
-
#version_tag_local ⇒ String
The version_tag_local method retrieves the Git revision hash for the current version tag.
-
#version_tag_remote ⇒ String
The version_tag_remote method retrieves the Git revision hash for the remote version tag.
-
#version_tag_task ⇒ Object
The version_tag_task method defines a Rake task that creates a Git tag for the current version.
-
#version_task ⇒ Object
The version_task method defines a Rake task that generates a version file for the gem.
-
#versions ⇒ Array<String>
The versions method retrieves and processes the list of git tags that match semantic versioning patterns.
-
#write_gemfile ⇒ Object
The write_gemfile method creates and writes the default Gemfile content if it doesn’t exist.
-
#write_ignore_file ⇒ Object
The write_ignore_file method writes the current ignore_files configuration to a .gitignore file in the project root directory.
-
#yard_dir ⇒ String
The yard_dir attribute accessor for configuring the output directory for YARD documentation.
-
#yard_doc_task ⇒ Object
The yard_doc_task method configures and sets up a YARD documentation generation task.
-
#yard_task ⇒ Object
The yard_task method sets up and registers Rake tasks for generating and managing YARD documentation.
Methods included from Editor
#edit_file, #edit_temp_file, #find_editor
Methods included from OllamaSupport
#ollama, #ollama_generate, #ollama_model, #options
Methods included from Warn
Methods included from PromptTemplate
#default_changelog_prompt, #default_changelog_system_prompt, #default_git_release_prompt, #default_git_release_system_prompt, #default_version_bump_prompt, #default_version_bump_system_prompt
Methods included from Utils
#ask?, #xdg_config, #xdg_config_dir, #xdg_config_filename, #xdg_config_home
Constructor Details
#initialize {|gem_hadar| ... } ⇒ GemHadar
The initialize method sets up a new GemHadar instance and configures it using the provided block.
This method creates a new instance of the GemHadar class, initializes internal arrays for dependencies and development dependencies, and then evaluates the provided block in the context of the new instance to configure the gem settings.
97 98 99 100 101 |
# File 'lib/gem_hadar.rb', line 97 def initialize(&block) @dependencies = [] @development_dependencies = [] block and instance_eval(&block) end |
Instance Method Details
#assert_valid_link(name, orig_url) ⇒ String
The assert_valid_link method verifies that the provided URL is valid by checking if it returns an HTTP OK status after following redirects, unless project is still ‘developing`.
following redirects
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 |
# File 'lib/gem_hadar.rb', line 1952 def assert_valid_link(name, orig_url) developing and return orig_url url = orig_url begin response = Net::HTTP.get_response(URI.parse(url)) url = response['location'] end while response.is_a?(Net::HTTPRedirection) response.is_a?(Net::HTTPOK) or fail "#{orig_url.inspect} for #{name} has to be a valid link" orig_url end |
#bindir ⇒ String?
The bindir attribute accessor for configuring the gem’s binary directory.
This method sets up a DSL accessor for the bindir attribute, which specifies the directory where executable scripts (binaries) are installed when the gem is packaged and installed. It provides a way to define the location of the bin directory that will contain the gem’s executable files.
327 |
# File 'lib/gem_hadar.rb', line 327 dsl_accessor :bindir |
#build_task ⇒ Object
The build_task method defines a Rake task that orchestrates the complete build process for packaging the gem.
This method sets up a :build task that depends on the tasks specified in the build_task_dependencies accessor. It provides a convenient way to execute all necessary steps for building packages for a release with a single command.
670 671 672 673 |
# File 'lib/gem_hadar.rb', line 670 def build_task desc 'Build task (builds all packages for a release)' task :build => build_task_dependencies end |
#build_task_dependencies ⇒ Array<Symbol, String>
The build_task_dependencies method manages the list of dependencies for the build task.
This method sets up a DSL accessor for the build_task_dependencies attribute, which specifies the sequence of Rake tasks that must be executed when running the build task. These dependencies typically include cleaning previous builds, generating the gem specification, packaging the gem, and creating a version tag.
661 |
# File 'lib/gem_hadar.rb', line 661 dsl_accessor :build_task_dependencies, [ :clobber, :gemspec, :package, :'version:tag' ] |
#changelog(&block) ⇒ GemHadar::ChangelogConfig
The changelog method configures or retrieves the changelog settings for the gem project.
This method serves as an accessor for the changelog configuration, allowing the gem project to define settings related to changelog generation and management. When a block is provided, it initializes a new ChangelogConfig instance with the block’s configuration. If no block is provided and no existing changelog configuration exists, it creates a new default ChangelogConfig instance.
617 618 619 620 621 622 623 624 |
# File 'lib/gem_hadar.rb', line 617 def changelog(&block) if block @changelog = ChangelogConfig.new(&block) elsif !@changelog @changelog = ChangelogConfig.new {} end @changelog end |
#changes_task ⇒ Object
The changes_task method defines namespaced Rake tasks for generating changelogs.
This method sets up a hierarchical task structure under the :changes namespace that:
-
:changes - Show help for all changes tasks
-
:changes:pending - Show changes since last version tag
-
:changes:current - Show changes between two latest version tags
-
:changes:range - Show changes for a specific Git range
-
:changes:full - Generate complete changelog from first tag
-
:changes:add - Append to existing changelog file
-
:changes:added - Check if the current version was added to changelog file
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 |
# File 'lib/gem_hadar.rb', line 1679 def changes_task namespace :changes do desc 'Show changes since last version tag' task :pending do unless version_tag_list.any? raise 'Need at least one version tag to work' end last_version = version_tag_list.last if last_version puts GemHadar::ChangelogGenerator.new(self).generate(last_version, 'HEAD') else raise 'Need at least one version tag to work' end end desc 'Show changes between two latest version tags' task :current do unless version_tag_list.length >= 2 raise 'Need at least two version tags to work' end version1, version2 = version_tag_list.last(2) if version1 && version2 puts GemHadar::ChangelogGenerator.new(self).generate(version1, version2) else raise 'Need at least two version tags to work' end end desc 'Show changes for a specific Git range (e.g., v1.0.0..v1.2.0)' task :range do if ARGV.size == 2 and range = ARGV.pop and range =~ /\A(.+)\.\.(.+)\z/ range_from, range_to = $1, $2 from_spec = GemHadar::VersionSpec[range_from] to_spec = GemHadar::VersionSpec[range_to] unless from_spec.version? && to_spec.version? raise "Invalid version format: #{range_from} or #{range_to}" end GemHadar::ChangelogGenerator.new(self). generate_range(STDOUT, from_spec, to_spec) exit else raise "Need range of the form v1.2.3..v1.2.4" end end desc 'Generate complete changelog from first tag and output to file' task :full do if ARGV.size == 1 GemHadar::ChangelogGenerator.new(self).generate_full(STDOUT) elsif ARGV.size == 2 File.open(ARGV[1], ?w) do |file| GemHadar::ChangelogGenerator.new(self).generate_full(file) end else raise "Need a filename to write to" end end desc 'Append new entries to existing changelog file' task :add do filename = ARGV[1] || changelog.filename filename or next if count = GemHadar::ChangelogGenerator.new(self).add_to_file(filename) edit_file filename puts "#{count} changes were added to #{filename.inspect}." else puts "No new changes added to #{filename.inspect}." end end desc 'Edit the existing changelog file' task :edit do filename = ARGV[1] || changelog.filename filename or raise 'Need changelog file to edit' edit_file filename end desc 'Check if current version was added to the changelog' task :added do changelog.filename or next GemHadar::ChangelogGenerator.new(self).changelog_version_added?(version) and next v = GemHadar::VersionSpec[version].untag abort <<~EOT Version #{v} has not been documented in changelog #{changelog.filename.inspect} file. Execute rake #{bold{'changes:update'}}. to do so. EOT end desc 'Commit changes in changelog filename' task :commit do changelog.filename or next `git status --porcelain #{changelog.filename.inspect}`.empty? and next system "git add #{changelog.filename.inspect}" msg = changelog. || "n/a" system "git commit -m #{msg.inspect} #{changelog.filename.inspect}" if $?.success? puts "Successfully commited changes in changelog filename." else warn "Committing changes in changelog filename has failed!" end end desc 'Update changelog file if necessary' task :update => %i[ add commit ] end # Main changes task that shows help when called directly desc 'Generate changelogs using Git history and AI' task :changes do puts <<~EOT Changes Tasks: rake changes:pending Show changes since last version tag rake changes:current Show changes between two latest version tags rake changes:range <range> Show changes for a specific Git range (e.g., v1.0.0..v1.2.0) rake changes:full [file] Generate complete changelog from first tag rake changes:add [file] Append new entries to changelog file rake changes:added Check if current version was added to changelog rake changes:edit [file] Edit changelog file rake changes:commit Commit changes in changelog if any rake changes:update Add and commit changes to changelog Examples: rake changes:range v1.0.0..v1.2.0 rake changes:full # or rake changes:full CHANGES.md rake changes:add # or rake changes:add CHANGES.md rake changes:edit # or rake changes:edit CHANGES.md EOT end end |
#clean(*args) ⇒ FileList?
The clean method manages the CLEAN file list for Rake tasks.
When called without arguments, it returns the current CLEAN file list. When called with arguments, it adds the specified files to the CLEAN list.
699 700 701 702 703 704 705 |
# File 'lib/gem_hadar.rb', line 699 def clean(*args) if args.empty? CLEAN else CLEAN.include(*args) end end |
#clobber(*args) ⇒ FileList?
The clobber method manages the CLOBBER file list for Rake tasks.
When called without arguments, it returns the current CLOBBER file list. When called with arguments, it adds the specified files to the CLOBBER list.
716 717 718 719 720 721 722 |
# File 'lib/gem_hadar.rb', line 716 def clobber(*args) if args.empty? CLOBBER else CLOBBER.include(*args) end end |
#compile_task ⇒ Object
The compile_task method sets up a Rake task to compile project extensions.
This method creates a :compile task that iterates through the configured extensions and compiles them using the system’s make command.
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 |
# File 'lib/gem_hadar.rb', line 1473 def compile_task for file in extensions dir = File.dirname(file) clean File.join(dir, 'Makefile'), File.join(dir, '*.{bundle,o,so}') end desc "Compile extensions: #{extensions * ', '}" task :compile do for file in extensions dir, file = File.split(file) cd dir do ruby file sh make end end end end |
#config_task ⇒ Object
The config_task method creates a Rake task that displays the current GemHadar configuration.
This method sets up a :gem_hadar:config task under the Rake namespace that outputs detailed information about the gem’s configuration, including environment variables, API keys, Ollama settings, XDG configuration directory, general gem properties, build and development parameters, Git remotes, and AI prompt defaults.
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 |
# File 'lib/gem_hadar.rb', line 1602 def config_task namespace :gem_hadar do desc "Display current gem_hadar configuration" task :config do puts "=== GemHadar Configuration ===" # RubyGems if ENV['GEM_HOST_API_KEY'].present? puts "RubyGems API Key: *** (set)" else puts "RubyGems API Key: Not set" end # GitHub if ENV['GITHUB_API_TOKEN'].present? puts "GitHub API Token: *** (set)" else puts "GitHub API Token: Not set" end # Ollama puts "Ollama Model: #{ollama_model} (default is #{ollama_model_default})" if url = (ollama.base_url rescue nil)&.to_s puts "Ollama Base URL: #{url.inspect}" else puts "Ollama Base URL: Not set" end if ENV['OLLAMA_MODEL_OPTIONS'] puts "Ollama Model Options: #{ENV['OLLAMA_MODEL_OPTIONS']}" else puts "Ollama Model Options: Not set (using defaults)" end # XDG config app dir puts "XDG config app dir: #{xdg_config_dir('gem_hadar').to_s.inspect}" # General puts "Gem Name: #{name}" puts "Version: #{version}" # Build/Development puts "MAKE: #{ENV['MAKE'] || 'Not set (will use gmake or make)'}" puts "EDITOR: #{ENV['EDITOR'] || 'Not set (will use vi)'}" # Git puts "Git Remote(s): #{ENV['GIT_REMOTE'] || 'origin'}" # Other puts "Version Override: #{ENV['VERSION'] || 'Not set'}" puts "GitHub Release Enabled: #{ENV['GITHUB_RELEASE_ENABLED'] || 'Not set'}" puts "\n=== AI Prompt Configuration (Default Values) ===" arrow = ?⤵ puts bold{"version_bump_system_prompt.txt"} + "#{arrow}\n" + italic{default_version_bump_system_prompt} puts bold{"version_bump_prompt.txt"} + "#{arrow}\n#{default_version_bump_prompt}" puts bold{"git_release_system_prompt.txt"} + "#{arrow}\n" + italic{default_git_release_system_prompt} puts bold{"git_release_prompt.txt"} + "#{arrow}\n" + italic{default_git_release_prompt} puts bold{"changelog_system_prompt.txt"} + "#{arrow}\n" + italic{default_changelog_system_prompt} puts bold{"changelog_prompt.txt"} + "#{arrow}\n" + italic{default_changelog_prompt} puts "=== End Configuration ===" end end end |
#create_all_tasks ⇒ GemHadar
The create_all_tasks method sets up and registers all the Rake tasks for the gem project.
1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 |
# File 'lib/gem_hadar.rb', line 1820 def create_all_tasks default_task config_task changes_task build_task rvm_task version_task version_show_task version_diff_task gem_hadar_update_task gemspec_task gems_install_task if test_dir test_task rcov_task end spec_task package_task yard_task install_library_task version_bump_task version_tag_task push_task release_task github_workflows_task write_ignore_file write_gemfile if extensions.full? compile_task task :prepare_install => :compile else task :prepare_install end self end |
#create_git_release_body ⇒ String
The create_git_release_body method generates a changelog for a GitHub release by analyzing the git diff between the previous version and the current HEAD.
It retrieves the log differences, fetches or uses default system and prompt templates, and utilizes an AI model to produce a formatted changelog entry.
1354 1355 1356 1357 1358 1359 |
# File 'lib/gem_hadar.rb', line 1354 def create_git_release_body log_diff = version_log_diff(to_version: version) system = xdg_config('gem_hadar', 'release_system_prompt.txt', default_git_release_system_prompt) prompt = xdg_config('gem_hadar', 'release_prompt.txt', default_git_release_prompt) % { name:, version:, log_diff: } ollama_generate(system:, prompt:) end |
#create_github_workflow_templates ⇒ Object
The create_github_workflow_templates method compiles GitHub Actions workflow templates from ERB files into actual YAML workflow files in the project’s .github/workflows directory
This method iterates through the configured GitHub workflows, processes each ERB template file using the template compilation system, and generates the corresponding workflow files in the standard GitHub Actions directory structure
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 |
# File 'lib/gem_hadar.rb', line 2117 def create_github_workflow_templates src_dir = Pathname.new(__dir__).join('gem_hadar', 'github_workflows') dst_dir = Pathname.pwd.join('.github', 'workflows') templates = Set[] github_workflows.each do |workflow, variables| @github_workflows_variables = variables src = src_dir.join(workflow + '.erb') unless src.exist? warn "Workflow template #{src.to_s.inspect} doesn't exist! => Skipping." end mkdir_p dst_dir, verbose: false dst = dst_dir.join(workflow) templates << template(src, dst) {} end templates.to_a end |
#default_task ⇒ Object
The default_task method defines the default Rake task for the gem project.
This method sets up a Rake task named :default that depends on the tasks specified in the default_task_dependencies accessor. It provides a convenient way to run the most common or essential tasks for the project with a single command.
645 646 647 648 |
# File 'lib/gem_hadar.rb', line 645 def default_task desc 'Default task' task :default => default_task_dependencies end |
#default_task_dependencies ⇒ Array<Symbol, String>
The default_task_dependencies method manages the list of dependencies for the default Rake task.
This method sets up a DSL accessor for the default_task_dependencies attribute, which specifies the sequence of Rake tasks that must be executed when running the default task. These dependencies typically include generating the gem specification and running tests to ensure a consistent starting point for development workflows.
637 |
# File 'lib/gem_hadar.rb', line 637 dsl_accessor :default_task_dependencies, [ :gemspec, :test ] |
#dependency(*args) ⇒ Object
The dependency method adds a new runtime dependency to the gem.
769 770 771 |
# File 'lib/gem_hadar.rb', line 769 def dependency(*args) @dependencies << args end |
#description ⇒ String
The description attribute accessor for configuring the gem’s description.
This method sets up a DSL accessor for the description attribute, which specifies the detailed explanation of what the gem does. It includes a validation step that raises an ArgumentError if the description has not been set, ensuring that the gem configuration contains this required information.
250 |
# File 'lib/gem_hadar.rb', line 250 dsl_accessor :description do has_to_be_set :description end |
#determine_version_range ⇒ Array(String, String)
Determine the start and end versions for diff comparison.
If the VERSION env var is set, it will be used as the starting version tag. Otherwise, it defaults to the current commit’s version or the latest tag.
1883 1884 1885 1886 1887 1888 1889 |
# File 'lib/gem_hadar.rb', line 1883 def determine_version_range = versions.map { GemHadar::VersionSpec[_1].tag } + %w[ HEAD ] found_version_tag = .index(GemHadar::VersionSpec[version].tag) found_version_tag.nil? and fail "cannot find version tag #{GemHadar::VersionSpec[version].tag}" start_version, end_version = [found_version_tag, 2] return start_version, end_version end |
#developing ⇒ Boolean
The developing attribute accessor for configuring development mode.
This method sets up a DSL accessor for the developing attribute, which controls whether the gem is in development mode. When set to true, certain behaviors such as skipping gem pushes are enabled as well as asserting the validity of the homepage link.
121 |
# File 'lib/gem_hadar.rb', line 121 dsl_accessor :developing, false |
#development_dependency(*args) ⇒ Object
The development_dependency method adds a new development-time dependency to the gem.
777 778 779 |
# File 'lib/gem_hadar.rb', line 777 def development_dependency(*args) @development_dependencies << args end |
#doc_code_files ⇒ FileList
The doc_code_files method manages the list of code files to be included in documentation generation.
This method sets up a DSL accessor for the doc_code_files attribute, which specifies the Ruby source files that should be processed when generating YARD documentation. It defaults to using the files attribute and provides a way to customize which code files are included in the documentation build process.
422 423 424 |
# File 'lib/gem_hadar.rb', line 422 dsl_accessor :doc_code_files do files end |
#doc_files ⇒ FileList
The doc_files attribute accessor for configuring additional documentation files.
This method sets up a DSL accessor for the doc_files attribute, which specifies additional files to be included in the YARD documentation generation process. It defaults to an empty FileList and provides a way to define extra documentation files that should be processed alongside the standard library source files.
documentation
437 438 439 |
# File 'lib/gem_hadar.rb', line 437 dsl_accessor :doc_files do FileList[File.join('lib/**/*.rb')] + FileList[File.join('ext/**/*.c')] end |
#email ⇒ String
The email attribute accessor for configuring the gem’s author email.
This method sets up a DSL accessor for the email attribute, which specifies the contact email address for the gem’s author. It includes a validation step that raises an ArgumentError if the email has not been set, ensuring that the gem configuration contains this required information.
203 204 205 |
# File 'lib/gem_hadar.rb', line 203 dsl_accessor :email do has_to_be_set :email end |
#executables ⇒ Set<String>
The executables attribute accessor for configuring the gem’s executable files.
This method sets up a DSL accessor for the executables attribute, which specifies the list of executable scripts that should be installed as part of the gem. It provides a way to define one or more executable file names that will be made available in the gem’s bin directory when the gem is installed.
the gem
340 |
# File 'lib/gem_hadar.rb', line 340 dsl_accessor :executables do Set[] end |
#extensions ⇒ FileList
The extensions attribute accessor for configuring project extensions.
This method sets up a DSL accessor for the extensions attribute, which specifies the list of extension configuration files (typically extconf.rb) that should be compiled when building the gem. It defaults to finding all extconf.rb files within the ext directory and its subdirectories, making it easy to include native extensions in the gem package.
464 |
# File 'lib/gem_hadar.rb', line 464 dsl_accessor :extensions do FileList['ext/**/extconf.rb'] end |
#files ⇒ Array<String>
The files attribute accessor for configuring the list of files included in the gem package.
This method sets up a DSL accessor for the files attribute, which specifies the complete set of files that should be included when building the gem package. It defaults to retrieving the file list from Git using ‘git ls-files` and provides a way to override this behavior through the configuration block.
490 491 492 |
# File 'lib/gem_hadar.rb', line 490 dsl_accessor :files do FileList[`git ls-files`.split("\n")] end |
#gem_files ⇒ Array<String>
The gem_files method returns an array of files that are included in the gem package.
It calculates this by subtracting the files listed in package_ignore_files from the list of all files.
2039 2040 2041 |
# File 'lib/gem_hadar.rb', line 2039 def gem_files (files.to_a - package_ignore_files.to_a) end |
#gem_hadar_update_task ⇒ Object
The gem_hadar_update_task method defines a Rake task that updates the gem_hadar dependency version in the gemspec file.
This method creates a :gem_hadar:update task under the Rake namespace that prompts the user to specify a new gem_hadar version. It then reads the existing gemspec file, modifies the version constraint for the gem_hadar dependency, and writes the updated content back to the file. If the specified version is already present in the gemspec, it skips the update and notifies the user.
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
# File 'lib/gem_hadar.rb', line 935 def gem_hadar_update_task namespace :gem_hadar do desc 'Update gem_hadar to a different version' task :update do answer = ask?("Which gem_hadar version? ", /^((?:\d+.){2}(?:\d+))$/) unless answer abort "Invalid version specification!" end gem_hadar_version = answer[0] filename = "#{name}.gemspec" old_data = File.read(filename) new_data = old_data.gsub( /(add_(?:development_)?dependency\(%q<gem_hadar>, \["~> )([\d.]+)("\])/ ) { "#$1#{gem_hadar_version}#$3" } if old_data == new_data warn "#{filename.inspect} already depends on gem_hadar "\ "#{gem_hadar_version} => Do nothing." else warn "Upgrading #{filename.inspect} to #{gem_hadar_version}." secure_write(filename) do |spec| spec.write new_data end end end end end |
#gem_push_task ⇒ Object
The gem_push_task method defines a Rake task for pushing the generated gem file to RubyGems.
This method sets up a :gem:push task under the Rake namespace that handles the process of uploading the gem package to RubyGems. It checks if the project is in developing mode and skips the push operation if so. Otherwise, it verifies the existence of the gem file, prompts the user for confirmation before pushing, and uses the gem push command with an optional API key from the environment. If the gem file does not exist or the user declines to push, appropriate messages are displayed and the task exits accordingly.
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 |
# File 'lib/gem_hadar.rb', line 1301 def gem_push_task namespace :gem do path = "pkg/#{name_version}.gem" desc "Push gem file #{File.basename(path)} to rubygems" if developing task :push => :build do puts "Skipping push to rubygems while developing mode is enabled." end else task :push => :build do if File.exist?(path) if ask?("Do you really want to push #{path.inspect} to rubygems? "\ "(yes/NO) ", /\Ayes\z/i) then key = ENV['GEM_HOST_API_KEY'].full? { |k| "--key #{k} " } sh "gem push #{key}#{path}" else exit 1 end else abort "Cannot push gem to rubygems: #{path.inspect} doesn't exist." end end end end end |
#gems_install_task(&block) ⇒ Object
The gems_install_task method defines a Rake task for installing all gem dependencies specified in the Gemfile.
This method sets up a :gems:install task that executes a block to install gems. If no block is provided, it defaults to running ‘bundle install’.
788 789 790 791 792 793 794 |
# File 'lib/gem_hadar.rb', line 788 def gems_install_task(&block) block ||= proc { sh 'bundle install' } desc 'Install all gems from the Gemfile' namespace :gems do task :install => :gemspec , &block end end |
#gemspec ⇒ Gem::Specification
The gemspec method creates and returns a new Gem::Specification object that defines the metadata and dependencies for the gem package.
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 |
# File 'lib/gem_hadar.rb', line 1968 def gemspec Gem::Specification.new do |s| s.name = name s.version = ::Gem::Version.new(GemHadar::VersionSpec[version].untag) s. = s.email = email s.homepage = assert_valid_link(:homepage, homepage) s.summary = summary s.description = description gem_files.full? { |f| s.files = Array(f) } test_files.full? { |t| s.test_files = Array(t) } extensions.full? { |e| s.extensions = Array(e) } bindir.full? { |b| s.bindir = b } executables.full? { |e| s.executables = Array(e) } licenses.full? { |l| s.licenses = Array(licenses) } .full? { |m| s. = m } required_ruby_version.full? { |v| s.required_ruby_version = v } s.add_development_dependency('gem_hadar', ">= #{VERSION}") for d in @development_dependencies s.add_development_dependency(*d) end for d in @dependencies if s.respond_to?(:add_runtime_dependency) s.add_runtime_dependency(*d) else s.add_dependency(*d) end end require_paths.full? { |r| s.require_paths = Array(r) } if title s. << '--title' << title else s. << '--title' << "#{name.camelize} - #{summary}" end if readme if File.exist?(readme) s. << '--main' << readme s.extra_rdoc_files << readme else warn "Add a #{readme} file to document your gem!" end end doc_files.full? { |df| s.extra_rdoc_files.concat Array(df) } end end |
#gemspec_task ⇒ Object
The gemspec_task method defines a Rake task that generates and writes a gemspec file for the project.
This method creates a :gemspec task that depends on the :version task, ensuring the version is set before generating the gemspec. It constructs the filename based on the project name, displays a warning message indicating the file being written, and uses secure_write to create the gemspec file with content generated by the gemspec method.
970 971 972 973 974 975 976 977 |
# File 'lib/gem_hadar.rb', line 970 def gemspec_task desc 'Create a gemspec file' task :gemspec => :version do filename = "#{name}.gemspec" warn "Writing to #{filename.inspect} for #{version}" secure_write(filename, gemspec.to_ruby) end end |
#git_remote ⇒ Object
The git_remote method retrieves the primary Git remote name configured for the project.
It first checks the GIT_REMOTE environment variable for a custom remote specification. If not set, it defaults to ‘origin’. When multiple remotes are specified in the environment variable, only the first one is returned.
1201 1202 1203 |
# File 'lib/gem_hadar.rb', line 1201 def git_remote ENV.fetch('GIT_REMOTE', 'origin').split(/\s+/).first end |
#git_remotes ⇒ Array<String>
The git_remotes method retrieves the list of remote repositories configured for the current Git project.
It first attempts to read the remotes from the ENV environment variable, splitting it by whitespace. If this is not available, it falls back to querying the local Git repository using ‘git remote`.
2026 2027 2028 2029 2030 |
# File 'lib/gem_hadar.rb', line 2026 def git_remotes remotes = ENV['GIT_REMOTE'].full?(:split, /\s+/) remotes or remotes = `git remote`.lines.map(&:chomp) remotes end |
#git_remotes_task ⇒ Object
The git_remotes_task method defines a Rake task that displays all Git remote repositories configured for the project.
This method sets up a :git_remotes task under the Rake namespace that retrieves and prints the list of Git remotes along with their URLs. It uses the git_remotes method to obtain the remote names and then fetches each remote’s URL using the ‘git remote get-url` command. The output is formatted to show each remote name followed by its corresponding URL on separate lines.
1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/gem_hadar.rb', line 1337 def git_remotes_task task :git_remotes do puts git_remotes.map { |r| url = `git remote get-url #{r.inspect}`.chomp "#{r} #{url}" } end end |
#github_release_task ⇒ Object
The github_release_task method defines a Rake task that creates a GitHub release for the current version.
This method sets up a :github:release task that prompts the user to confirm publishing a release message on GitHub. It retrieves the GitHub API token from the environment, derives the repository owner and name from the git remote URL, generates a changelog using AI, and creates the release via the GitHub API.
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 |
# File 'lib/gem_hadar.rb', line 1369 def github_release_task namespace :github do unless github_api_token = ENV['GITHUB_API_TOKEN'].full? warn "GITHUB_API_TOKEN not set. => Skipping github release task." task :release return end desc "Create a new GitHub release for the current version with a AI-generated changelog" task :release do yes = ask?( "Do you want to publish a release message on github? (y/n%{default}) ", /\Ay/i, default: ENV['GITHUB_RELEASE_ENABLED'] ) unless yes warn "Skipping publication of a github release message." next end if %r(\A/*(?<owner>[^/]+)/(?<repo>[^/.]+)) =~ github_remote_url&.path rc = GitHub::ReleaseCreator.new(owner:, repo:, token: github_api_token) tag_name = GemHadar::VersionSpec[version].tag target_commitish = `git show -s --format=%H #{tag_name.inspect}^{commit}`.chomp body = edit_temp_file(create_git_release_body) if body.present? begin response = rc.perform(tag_name:, target_commitish:, body:) puts "Release created successfully! See #{response.html_url}" rescue => e warn e. end else warn "Skipping creation of github release message." end else warn "Could not derive github remote url from git remotes. => Skipping github release task." end end end end |
#github_remote_url ⇒ URI?
The github_remote_url method retrieves and parses the GitHub remote URL from the local Git configuration.
It executes ‘git remote -v` to get all remote configurations, extracts the push URLs, processes them to construct valid URIs, and returns the first URI pointing to GitHub.com.
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 |
# File 'lib/gem_hadar.rb', line 2068 def github_remote_url if remotes = `git remote -v` remotes_urls = remotes.scan(/^(\S+)\s+(\S+)\s+\(push\)/) remotes_uris = remotes_urls.map do |name, url| if %r(\A(?<scheme>[^@]+)@(?<hostname>[A-Za-z0-9.]+):(?:\d*)(?<path>.*)) =~ url path = ?/ + path unless path.start_with? ?/ url = 'ssh://%s@%s%s' % [ scheme, hostname, path ] # approximate correct URIs end URI.parse(url) end remotes_uris.find { |uri| uri.hostname == 'github.com' } end end |
#github_workflows ⇒ Hash
The github_workflows attribute accessor for configuring GitHub Actions workflows.
This method sets up a DSL accessor for the github_workflows attribute, which specifies the configuration for generating GitHub Actions workflow files from ERB templates. It provides a way to define which workflows to generate and the variables to use when rendering the templates.
2092 2093 2094 |
# File 'lib/gem_hadar.rb', line 2092 dsl_accessor :github_workflows do {} end |
#github_workflows_task ⇒ Object
The github_workflows_task method sets up Rake tasks for generating GitHub Actions workflow files from ERB templates.
This method configures a hierarchical task structure under the :github namespace that:
-
Compiles configured workflow templates from ERB files into actual workflow YAML files
-
Creates a :workflows task that depends on all compiled template files
-
Sets up a :workflows:clean task to remove generated workflow files
-
Uses the github_workflows configuration to determine which workflows to generate
-
Applies template variables to customize the generated workflows
2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 |
# File 'lib/gem_hadar.rb', line 2147 def github_workflows_task namespace :github do desc "Create all configured github workflow tasks" task :workflows => create_github_workflow_templates namespace :workflows do desc "Delete all created github workflows" task :clean do dst_dir = Pathname.pwd.join('.github', 'workflows') github_workflows.each_key do |workflow| rm_f dst_dir.join(workflow), verbose: true end end end end end |
#github_workflows_variables ⇒ Hash
The github_workflows_variables method retrieves the cached variables used for GitHub Actions workflow template compilation.
This method returns the stored hash of variables that were previously set during the configuration of GitHub workflows. If no variables have been set, it returns an empty hash as a default value.
2105 2106 2107 |
# File 'lib/gem_hadar.rb', line 2105 def github_workflows_variables @github_workflows_variables || {} end |
#has_to_be_set(name) ⇒ Object
The has_to_be_set method raises an error if a required gem configuration attribute is not set.
109 110 111 |
# File 'lib/gem_hadar.rb', line 109 def has_to_be_set(name) fail "#{self.class}: #{name} has to be set for gem" end |
#homepage ⇒ String
The homepage attribute accessor for configuring the gem’s homepage URL.
This method sets up a DSL accessor for the homepage attribute, which specifies the URL of the gem’s official repository or project page. It includes a validation step that raises an ArgumentError if the homepage has not been set, ensuring that the gem configuration contains this required information. When the developing flag is false, it also validates that the provided URL returns an HTTP OK status after following redirects.
220 221 222 |
# File 'lib/gem_hadar.rb', line 220 dsl_accessor :homepage do has_to_be_set :homepage end |
#ignore(*args) ⇒ Set<String>?
The ignore method manages the list of files to be ignored by the gem.
When called without arguments, it returns the current set of ignored files. When called with arguments, it adds the specified files to the ignore list.
733 734 735 736 737 738 739 |
# File 'lib/gem_hadar.rb', line 733 def ignore(*args) if args.empty? ignore_files else args.each { |a| ignore_files << a } end end |
#ignore_files ⇒ Set<String>
The ignore_files attribute accessor for configuring files to be ignored by the gem.
This method sets up a DSL accessor for the ignore_files attribute, which specifies a set of file patterns that should be excluded from various gem operations and processing tasks. It provides a way to define ignore rules that apply broadly across the gem’s functionality, including but not limited to build processes, documentation generation, and version control integration.
317 |
# File 'lib/gem_hadar.rb', line 317 dsl_accessor :ignore_files do Set[] end |
#install_library(&block) ⇒ Object
The install_library method sets up a Rake task for installing the library or executable into site_ruby directories.
This method configures an :install task that depends on the :prepare_install task and executes the provided block. It stores the block in an instance variable to be called later when the task is executed.
683 684 685 686 687 688 |
# File 'lib/gem_hadar.rb', line 683 def install_library(&block) @install_library_block = -> do desc 'Install executable/library into site_ruby directories' task :install => :prepare_install, &block end end |
#install_library_task ⇒ Object
The install_library_task method executes the installed library task block if it has been defined.
995 996 997 |
# File 'lib/gem_hadar.rb', line 995 def install_library_task @install_library_block.full?(:call) end |
#licenses ⇒ Set<String>
The licenses attribute accessor for configuring the gem’s license information.
This method sets up a DSL accessor for the licenses attribute, which specifies the license(s) under which the gem is distributed. It provides a way to define one or more licenses that apply to the gem, defaulting to an empty Set if none are explicitly configured.
351 |
# File 'lib/gem_hadar.rb', line 351 dsl_accessor :licenses do Set[] end |
#make ⇒ String?
The make method retrieves the make command to be used for building extensions.
This method determines the appropriate make command to use when compiling project extensions. It first checks for the MAKE environment variable and returns its value if set. If the environment variable is not set, it attempts to detect a suitable make command by testing for the existence of ‘gmake’ and ‘make’ in the system PATH.
476 477 478 |
# File 'lib/gem_hadar.rb', line 476 dsl_accessor :make do ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') } end |
#master_prepare_task ⇒ Object
The master_prepare_task method defines a Rake task that sets up a remote Git repository for the project.
This method creates a :master:prepare task under the Rake namespace that guides the user through creating a new bare Git repository on a remote server via SSH. It prompts for the remote name, directory path, and SSH account details to configure the repository and establish a connection back to the local project.
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 |
# File 'lib/gem_hadar.rb', line 1213 def master_prepare_task namespace :master do desc "Prepare a remote git repository for this project" task :prepare do puts "Create a new remote git repository for #{name.inspect}" remote_name = ask?('Name (default: origin) ? ', /^.+$/). full?(:[], 0) || 'origin' dir = ask?("Directory (default: /git/#{name}.git)? ", /^.+$/). full?(:[], 0) || "/git/#{name}.git" ssh_account = ask?('SSH account (format: login@host)? ', /^[^@]+@[^@]+/). full?(:[], 0) || exit(1) sh "ssh #{ssh_account} 'git init --bare #{dir}'" sh "git remote add -m master #{remote_name} #{ssh_account}:#{dir}" end end end |
#master_push_task ⇒ Object
The master_push_task method defines Rake tasks for pushing the master branch to configured Git remotes.
This method sets up a hierarchical task structure under the :master namespace:
-
It creates subtasks in the :master:push namespace for each configured Git remote, allowing individual pushes to specific remotes.
-
It also defines a top-level :master:push task that depends on all the individual remote push tasks, enabling a single command to push the master branch to all remotes.
The tasks utilize the git_remotes method to determine which remotes are configured and generate appropriate push commands for each one.
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 |
# File 'lib/gem_hadar.rb', line 1274 def master_push_task namespace :master do git_remotes.each do |gr| namespace gr.to_sym do desc "Push master to git remote #{gr}" task :push do sh "git push #{gr} master" end end end desc "Push master #{version} to all git remotes: #{git_remotes * ' '}" task :push => git_remotes.map { |gr| :"master:#{gr}:push" } end end |
#modified_task ⇒ Object
The modified_task method defines a Rake task that checks for uncommitted changes in the Git repository
This method creates a Rake task named :modified that runs a Git status command to identify any modified files that are not yet committed. If any changed files are found, it aborts the task execution and displays a message listing all the uncommitted files
1416 1417 1418 1419 1420 1421 1422 1423 |
# File 'lib/gem_hadar.rb', line 1416 def modified_task task :modified do changed_files = `git status --porcelain`.gsub(/^\s*\S\s+/, '').lines unless changed_files.empty? abort "There are still modified files:\n#{changed_files * ''}" end end end |
#module_type ⇒ Symbol
The module_type attribute accessor for configuring the type of Ruby construct to generate for version code.
This method sets up a DSL accessor for the module_type attribute, which determines whether the generated code structure for the version module should be a :module or :class. This controls the type of Ruby construct created when generating code skeletons and version files. The value can be set to either:
-
:module (default) - Generates module-based structure
-
:class - Generates class-based structure
This is used in the generated version.rb file to create either:
module MyGem
# ... version constants
end
or
class MyGem
# ... version constants
end
175 |
# File 'lib/gem_hadar.rb', line 175 dsl_accessor :module_type, :module |
#name ⇒ String
The name attribute accessor for configuring the gem’s name.
This method sets up a DSL accessor for the name attribute, which specifies the identifier for the gem. It includes a validation step that raises an ArgumentError if the name has not been set, ensuring that the gem configuration contains a required name value.
133 134 135 |
# File 'lib/gem_hadar.rb', line 133 dsl_accessor :name do has_to_be_set :name end |
#name_version ⇒ String
The name_version method computes and returns the combined gem name and version string.
This method constructs a version identifier by joining the gem’s name and current version with a hyphen separator. It is typically used to generate filenames or identifiers that incorporate both the gem name and its version number for packaging, tagging, or display purposes.
146 147 148 |
# File 'lib/gem_hadar.rb', line 146 dsl_accessor :name_version do [ name, version ] * '-' end |
#ollama_model_default ⇒ String
The ollama_model_default method returns the default name of the Ollama AI model to be used for generating responses when no custom model is specified.
1861 |
# File 'lib/gem_hadar.rb', line 1861 dsl_accessor :ollama_model_default, 'llama3.1'.freeze |
#package_ignore(*args) ⇒ Set<String>?
The package_ignore method manages the list of files to be ignored during gem packaging.
When called without arguments, it returns the current set of package ignore files. When called with arguments, it adds the specified file patterns to the package ignore list.
752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/gem_hadar.rb', line 752 def package_ignore(*args) if args.empty? package_ignore_files else args.each do |arg| if File.directory?(arg) package_ignore_files.merge FileList['%s/**/*' % arg] else package_ignore_files << arg end end end end |
#package_ignore_files ⇒ Set<String>
The package_ignore_files attribute accessor for configuring files to be ignored during gem packaging.
This method sets up a DSL accessor for the package_ignore_files attribute, which specifies file patterns that should be excluded from the gem package when it is built. It defaults to an empty set and provides a way to define ignore rules specific to the packaging process, separate from general project ignore rules.
504 505 506 |
# File 'lib/gem_hadar.rb', line 504 dsl_accessor :package_ignore_files do Set[] end |
#package_task ⇒ Object
The package_task method sets up a Rake task for packaging the gem.
This method configures a task that creates a package directory, initializes a Gem::PackageTask with the current gem specification, and specifies that tar files should be created. It also includes the files to be packaged by adding gem_files to the package_files attribute of the Gem::PackageTask.
985 986 987 988 989 990 991 |
# File 'lib/gem_hadar.rb', line 985 def package_task clean 'pkg' Gem::PackageTask.new(gemspec) do |pkg| pkg.need_tar = true pkg.package_files += gem_files end end |
#path_module ⇒ String
The path_module attribute accessor for configuring the Ruby module name.
This method sets up a DSL accessor for the path_module attribute, which determines the camelized version of the gem’s name to be used as the Ruby module or class name. It automatically converts the value of path_name into CamelCase format, ensuring consistency with Ruby naming conventions for module and class declarations.
529 |
# File 'lib/gem_hadar.rb', line 529 dsl_accessor :path_module do path_name.camelize end |
#path_name ⇒ String
The path_name attribute accessor for configuring the gem’s path name.
This method sets up a DSL accessor for the path_name attribute, which determines the raw gem name value used for generating file paths and module names. It defaults to the value of the name attribute and is particularly useful for creating consistent directory structures and file naming conventions. This value is used internally by GemHadar to create the root directory for the gem and generate a version.rb file in that location.
518 |
# File 'lib/gem_hadar.rb', line 518 dsl_accessor :path_name do name end |
#post_install_message ⇒ String?
The post_install_message attribute accessor for configuring a message to display after gem installation.
This method sets up a DSL accessor for the post_install_message attribute, which specifies a message to be displayed to users after the gem is installed. This can be useful for providing additional information, usage instructions, or important warnings to users of the gem.
570 |
# File 'lib/gem_hadar.rb', line 570 dsl_accessor :post_install_message |
#push_task ⇒ Object
The push_task method defines a Rake task that orchestrates the complete process of pushing changes and artifacts to remote repositories and package managers.
This method sets up multiple subtasks including preparing the master branch, pushing version tags, pushing to gem repositories, and creating GitHub releases. It also includes a check for uncommitted changes before proceeding with the push operations.
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 |
# File 'lib/gem_hadar.rb', line 1445 def push_task master_prepare_task version_push_task master_push_task gem_push_task git_remotes_task github_release_task modified_task desc "Push all changes for version #{version} into the internets." task :push => push_task_dependencies end |
#push_task_dependencies ⇒ Array<Symbol, String>
The push_task_dependencies method manages the list of dependencies for the push task.
This method sets up a DSL accessor for the push_task_dependencies attribute, which specifies the sequence of Rake tasks that must be executed when running the push task. These dependencies typically include checks for modified files, building the gem, pushing to remote repositories, and publishing to package managers like RubyGems and GitHub.
1435 |
# File 'lib/gem_hadar.rb', line 1435 dsl_accessor :push_task_dependencies, %i[ modified build master:push version:push gem:push github:release ] |
#rcov_task ⇒ Object
The rcov_task method sets up a Rake task for executing code coverage tests using RCov.
This method configures a :rcov task that runs the project’s test suite with RCov to generate code coverage reports. It includes the test directory and required paths in the load path, specifies the test files to run, and enables verbose output. The task also conditionally depends on the :compile task if project extensions are present. If RCov is not available, it displays a warning message suggesting to install RCov.
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/gem_hadar.rb', line 1044 def rcov_task if defined?(::Rcov) rt = ::Rcov::RcovTask.new(:run_rcov) do |t| t.libs << test_dir t.libs.concat require_paths.to_a t.libs.uniq! t.test_files = test_files t.verbose = true t.rcov_opts = %W[-x '\\b#{test_dir}\/' -x '\\bgems\/'] end desc 'Run the rcov code coverage tests' task :rcov => [ (:compile if extensions.full?), rt.name ].compact clobber 'coverage' else desc 'Run the rcov code coverage tests' task :rcov do warn "rcov doesn't work for some reason, have you tried 'gem install rcov'?" end end end |
#readme ⇒ String?
The readme attribute accessor for configuring the gem’s README file.
This method sets up a DSL accessor for the readme attribute, which specifies the path to the README file for the gem. It provides a way to define the location of the README file that will be used in documentation and packaging processes.
294 |
# File 'lib/gem_hadar.rb', line 294 dsl_accessor :readme |
#release_task ⇒ Object
The release_task method defines a Rake task that orchestrates the complete release process for the gem.
This method sets up a :release task that depends on the :push task, ensuring all necessary steps for publishing the gem are executed in sequence. It provides a convenient way to perform a full release workflow with a single command.
1464 1465 1466 1467 |
# File 'lib/gem_hadar.rb', line 1464 def release_task desc "Release the new version #{version} for the gem #{name}." task :release => [ :'changes:added', :push ] end |
#require_path(path = nil) ⇒ String
The require_path method manages the gem’s require path configuration.
This method provides functionality to set or retrieve the directory paths from which the gem’s code can be loaded. When called with a path argument, it updates the require_paths attribute with that path and returns it. When called without arguments, it returns the first path from the current require_paths set.
path when retrieving
277 278 279 280 281 282 283 284 |
# File 'lib/gem_hadar.rb', line 277 def require_path(path = nil) if path self.require_paths = Set[path] path else require_paths.first end end |
#require_paths ⇒ Set<String>
The require_paths attribute accessor for configuring the gem’s require paths.
This method sets up a DSL accessor for the require_paths attribute, which specifies the directories from which the gem’s code can be loaded. It provides a way to define the locations of the library files that will be made available to users of the gem when it is required in Ruby programs.
path
262 |
# File 'lib/gem_hadar.rb', line 262 dsl_accessor :require_paths do Set['lib'] end |
#required_ruby_version ⇒ String?
The required_ruby_version attribute accessor for configuring the minimum Ruby version requirement.
This method sets up a DSL accessor for the required_ruby_version attribute, which specifies the minimum version of Ruby that the gem requires to run. It allows defining the Ruby version constraint that will be included in the gem specification.
581 |
# File 'lib/gem_hadar.rb', line 581 dsl_accessor :required_ruby_version |
#rvm(&block) ⇒ GemHadar::RvmConfig
The rvm method configures RVM (Ruby Version Manager) settings for the gem project.
This method initializes and returns an RvmConfig object that holds RVM-specific configuration such as the Ruby version to use and the gemset name. If a block is provided, it configures the RvmConfig object with the given settings. If no block is provided and no existing RvmConfig object exists, it creates a new one with default settings.
595 596 597 598 599 600 601 602 |
# File 'lib/gem_hadar.rb', line 595 def rvm(&block) if block @rvm = RvmConfig.new(&block) elsif !@rvm @rvm = RvmConfig.new { } end @rvm end |
#rvm_task ⇒ Object
The rvm_task method creates a .rvmrc file that configures RVM to use the specified Ruby version and gemset for the project.
This task generates a .rvmrc file in the project root directory with commands to:
-
Use the Ruby version specified by the rvm.use accessor
-
Create the gemset specified by the rvm.gemset accessor
-
Switch to using that gemset
The generated file is written using the secure_write method to ensure proper file permissions.
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 |
# File 'lib/gem_hadar.rb', line 1501 def rvm_task desc 'Create .rvmrc file' task :rvm do secure_write('.rvmrc') do |output| output.write <<~EOT rvm use #{rvm.use} rvm gemset create #{rvm.gemset} rvm gemset use #{rvm.gemset} EOT end end end |
#spec_dir ⇒ String?
The spec_dir attribute accessor for configuring the RSpec specification directory.
This method sets up a DSL accessor for the spec_dir attribute, which specifies the directory where RSpec test files are located. It provides a way to customize the location of test specifications separate from the default ‘spec’ directory, allowing for more flexible project structures.
nil if not set
391 |
# File 'lib/gem_hadar.rb', line 391 dsl_accessor :spec_dir |
#spec_pattern ⇒ String
The spec_pattern method configures the pattern used to locate RSpec test files.
This method sets up a DSL accessor for the spec_pattern attribute, which defines the file pattern used to discover RSpec test files in the project. It defaults to a standard pattern that looks for files ending in _spec.rb within the spec directory and its subdirectories, but can be customized through the configuration block.
403 404 405 406 407 408 409 |
# File 'lib/gem_hadar.rb', line 403 dsl_accessor :spec_pattern do if spec_dir "#{spec_dir}{,/*/**}/*_spec.rb" else 'spec{,/*/**}/*_spec.rb' end end |
#spec_task ⇒ Object
The spec_task method sets up a Rake task for executing RSpec tests.
This method configures a :spec task that runs the project’s RSpec test suite. It initializes an RSpec::Core::RakeTask with appropriate Ruby options, test pattern, and verbose output. The task also conditionally depends on the :compile task if project extensions are present.
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'lib/gem_hadar.rb', line 1024 def spec_task defined? ::RSpec::Core::RakeTask or return st = RSpec::Core::RakeTask.new(:run_specs) do |t| t.ruby_opts ||= '' t.ruby_opts << ' -I' << ([ spec_dir ] + require_paths.to_a).uniq * ':' t.pattern = spec_pattern t.verbose = true end task :spec => [ (:compile if extensions.full?), st.name ].compact end |
#summary ⇒ String
The summary attribute accessor for configuring the gem’s summary.
This method sets up a DSL accessor for the summary attribute, which specifies a brief description of what the gem does. It includes a validation step that raises an ArgumentError if the summary has not been set, ensuring that the gem configuration contains this required information.
235 236 237 |
# File 'lib/gem_hadar.rb', line 235 dsl_accessor :summary do has_to_be_set :summary end |
#test_dir ⇒ String?
The test_dir attribute accessor for configuring the test directory.
This method sets up a DSL accessor for the test_dir attribute, which specifies the directory where test files are located. It provides a way to define the location of the test directory that will be used by various testing tasks and configurations within the gem project.
361 |
# File 'lib/gem_hadar.rb', line 361 dsl_accessor :test_dir |
#test_files ⇒ FileList
The test_files attribute accessor for configuring the list of test files to be included in the gem package.
This method sets up a DSL accessor for the test_files attribute, which specifies the files that should be included when running tests for the gem. It provides a way to customize the test file discovery process, defaulting to finding all Ruby files ending in _spec.rb within the spec directory and its subdirectories.
373 374 375 376 377 378 379 |
# File 'lib/gem_hadar.rb', line 373 dsl_accessor :test_files do if test_dir FileList[File.join(test_dir, '**/*.rb')] else FileList.new end end |
#test_task ⇒ Object
The test_task method sets up a Rake task for executing the project’s test suite.
This method configures a Rake task named :test that runs the test suite using Rake::TestTask. It includes the test directory and required paths in the load path, specifies the test files to run, and enables verbose output. The task also conditionally depends on the :compile task if project extensions are present.
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/gem_hadar.rb', line 1007 def test_task tt = Rake::TestTask.new(:run_tests) do |t| t.libs << test_dir t.libs.concat require_paths.to_a t.test_files = test_files t.verbose = true end desc 'Run the tests' task :test => [ (:compile if extensions.full?), tt.name ].compact end |
#title ⇒ String?
The title attribute accessor for configuring the gem’s documentation title.
This method sets up a DSL accessor for the title attribute, which specifies the title to be used in the generated YARD documentation. It provides a way to define a custom title that will be included in the documentation output, making it easier to identify and reference the gem’s documentation.
304 |
# File 'lib/gem_hadar.rb', line 304 dsl_accessor :title |
#version ⇒ String
The version attribute accessor for configuring the gem’s version.
This method sets up a DSL accessor for the version attribute, which specifies the version number of the gem. It includes logic to determine the version from the VERSION file or an environment variable override, and will raise an ArgumentError if the version has not been set and cannot be determined.
543 544 545 546 547 548 |
# File 'lib/gem_hadar.rb', line 543 dsl_accessor :version do v = ENV['VERSION'].full? and next v File.read('VERSION').chomp rescue Errno::ENOENT has_to_be_set :version end |
#version_bump_task ⇒ Object
The version_bump_task method defines Rake tasks for incrementing the gem’s version number.
This method sets up a hierarchical task structure under the :version namespace:
-
It creates subtasks in the :version:bump namespace for explicitly bumping
major, minor, or build versions.
-
It also defines a :version:bump task that automatically suggests the
appropriate version bump type by analyzing recent changes using AI. The suggestion is based on the git log diff between the previous version and the current HEAD, and it prompts the user for confirmation before applying the bump.
The tasks utilize the version_log_diff method to gather change information, the ollama_generate method to get AI-powered suggestions, and the version_bump_to method to perform the actual version update.
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'lib/gem_hadar.rb', line 1082 def version_bump_task namespace :version do namespace :bump do desc 'Bump major version' task :major do version_bump_to(:major) end desc 'Bump minor version' task :minor do version_bump_to(:minor) end desc 'Bump build version' task :build do version_bump_to(:build) end end desc 'Bump version with AI suggestion' task :bump do log_diff = version_log_diff(from_version: nil, to_version: 'HEAD') system = xdg_config('gem_hadar', 'version_bump_system_prompt.txt', default_version_bump_system_prompt) prompt = xdg_config('gem_hadar', 'version_bump_prompt.txt', default_version_bump_prompt) % { version:, log_diff: } response = ollama_generate(system:, prompt:) puts response default = nil if response =~ /(major|minor|build)\s*$/ default = $1 end response = ask?( 'Bump a major, minor, or build version%{default}? ', /\A(major|minor|build)\z/, default: ) if version_type = response&.[](1) version_bump_to(version_type) else exit 1 end end end end |
#version_bump_to(type) ⇒ Object
Increases the specified part of the version number and writes it back to the VERSION file.
1867 1868 1869 1870 1871 1872 1873 |
# File 'lib/gem_hadar.rb', line 1867 def version_bump_to(type) type = type.to_sym version = File.read('VERSION').chomp.version version.bump(type) secure_write('VERSION') { |v| v.puts version } exit 0 end |
#version_diff_task ⇒ Object
The version_diff_task method defines Rake tasks for listing and displaying git version differences.
This method sets up two subtasks under the :version namespace:
-
A :list task that fetches all git tags, ensures the operation succeeds,
and outputs the sorted list of versions.
-
A :diff task that calculates the version range, displays a colored diff
between the versions, and shows the changes.
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
# File 'lib/gem_hadar.rb', line 908 def version_diff_task namespace :version do desc "List all versions in order" task :list do system 'git fetch --tags' $?.success? or exit $?.exitstatus puts versions end desc "Displaying the diff from env var VERSION to the next version or HEAD" task :diff do start_version, end_version = determine_version_range puts color(172) { "Showing diff from version %s to %s:" % [ start_version, end_version ] } puts `git diff --color=always #{start_version}..#{end_version}` end end end |
#version_epilogue ⇒ String?
The version_epilogue attribute accessor for configuring additional content to be appended to the version file.
This method sets up a DSL accessor for the version_epilogue attribute, which specifies extra content to be included at the end of the generated version file. This can be useful for adding custom comments, license information, or other supplementary data to the version module or class.
559 |
# File 'lib/gem_hadar.rb', line 559 dsl_accessor :version_epilogue |
#version_log_diff(to_version: 'HEAD', from_version: nil) ⇒ String
The version_log_diff method generates a git log output containing patch differences between two specified versions.
This method retrieves the commit history between a starting version and an ending version, including detailed changes (patch format) for each commit. It supports comparing against the current HEAD or specific version tags, and automatically determines the appropriate previous version when only a target version is provided.
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'lib/gem_hadar.rb', line 865 def version_log_diff(to_version: 'HEAD', from_version: nil) to_version = GemHadar::VersionSpec[to_version] from_version = from_version.full? { GemHadar::VersionSpec[from_version] } if to_version.head? if from_version.blank? from_version = versions.last else unless versions.find { |v| v == from_version } fail "Could not find #{from_version.inspect}." end end `git log -p #{from_version.tag}..HEAD` else unless versions.find { |v| v == to_version } fail "Could not find #{to_version.inspect}." end if from_version.blank? from_version = versions.each_cons(2).find do |previous_version, v| if v == to_version break previous_version end end unless from_version return `git log -p #{to_version.tag}` end else unless versions.find { |v| v == from_version } fail "Could not find #{from_version.inspect}." end end `git log -p #{from_version.tag}..#{to_version.tag}` end end |
#version_push_task ⇒ Object
The version_push_task method defines Rake tasks for pushing version tags to Git remotes.
This method sets up a hierarchical task structure under the :version namespace:
-
It creates subtasks in the :version:push namespace for each configured Git remote, allowing individual pushes to specific remotes.
-
It also defines a top-level :version:push task that depends on all the individual remote push tasks, enabling a single command to push the version tag to all remotes.
The tasks utilize the git_remotes method to determine which remotes are configured and generate appropriate push commands for each one.
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
# File 'lib/gem_hadar.rb', line 1244 def version_push_task namespace :version do git_remotes.each do |gr| namespace gr.to_sym do desc "Push version #{version} to git remote #{gr}" task :push do sh "git push #{gr} v#{version}" end end end desc "Push version #{version} to all git remotes: #{git_remotes * ' '}" task :push => git_remotes.map { |gr| :"version:#{gr}:push" } end end |
#version_show_task ⇒ Object
The version_show_task method defines a Rake task that displays the current version of the gem.
This method creates a :version:show task under the Rake namespace that reads the version from the generated version file in the lib directory and compares it with the version specified in the GemHadar configuration. It then outputs a message indicating whether the versions match or not.
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/gem_hadar.rb', line 832 def version_show_task namespace :version do desc "Displaying the current version" task :show do require path_name dir = File.join('lib', path_name) version_file = File.join(dir, 'version.rb') m = Module.new m.instance_eval File.read(version_file) version_rb = m.const_get( [ path_module, 'VERSION' ] * '::' ) equal = version == version_rb ? '==' : '!=' puts "version.rb=#{version_rb} #{equal} VERSION=#{version}" end end end |
#version_tag_list ⇒ Array<GemHadar::VersionSpec>
The version_tag_list method retrieves and processes semantic version tags from the Git repository.
This method fetches all Git tags from the repository, filters them to include only those that match semantic versioning patterns (containing three numeric components separated by dots), removes any ‘v’ prefix from the tags, and sorts the resulting version specifications in ascending order according to semantic versioning rules.
1911 1912 1913 1914 1915 |
# File 'lib/gem_hadar.rb', line 1911 def version_tag_list `git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/). map { |tag| GemHadar::VersionSpec[tag.chomp] }. sort_by(&:version) end |
#version_tag_local ⇒ String
The version_tag_local method retrieves the Git revision hash for the current version tag
This method executes a Git command to obtain the full revision hash (commit SHA) associated with the current gem version tag. It constructs the tag name using the GemHadar::VersionSpec class and then uses Git’s rev-parse command to resolve the tag to its corresponding commit.
1135 1136 1137 1138 |
# File 'lib/gem_hadar.rb', line 1135 def version_tag_local `git show-ref #{GemHadar::VersionSpec[version].tag.inspect}`. chomp.sub(/\s.*/, '').full? end |
#version_tag_remote ⇒ String
The version_tag_remote method retrieves the Git revision hash for the remote version tag
This method executes a Git command to obtain the full revision hash (commit SHA) associated with the current gem version tag on the remote repository. It constructs the tag name using the GemHadar::VersionSpec class and then uses Git’s ls-remote command to resolve the tag to its corresponding commit on the specified remote.
1151 1152 1153 1154 |
# File 'lib/gem_hadar.rb', line 1151 def version_tag_remote `git ls-remote --tags #{git_remote} #{GemHadar::VersionSpec[version].tag.inspect}`. chomp.sub(/\s.*/, '').full? end |
#version_tag_task ⇒ Object
The version_tag_task method defines a Rake task that creates a Git tag for the current version.
This method sets up a :version:tag task under the Rake namespace that creates an annotated Git tag for the project’s current version. It checks if a tag with the same name already exists and handles the case where the tag exists but is different from the current commit. If the tag already exists and is different, it prompts the user to confirm whether to overwrite it forcefully.
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
# File 'lib/gem_hadar.rb', line 1166 def version_tag_task namespace :version do namespace :tag do desc "show local tag revision" task :local do system 'git fetch --tags' puts version_tag_local end desc "show remote tag revision" task :remote do puts version_tag_remote end end desc "Tag this commit as version #{version}" task :tag => :modified do version_spec = GemHadar::VersionSpec[version] if sha = version_tag_remote abort <<~EOT.chomp Remote version tag #{version_spec.tag.inspect} already exists and points to #{sha.inspect}!" Call version:bump first to create a new version before release. EOT end sh "git tag -a -m 'Version #{version_spec.untag}' -f #{version_spec.tag.inspect}" end end end |
#version_task ⇒ Object
The version_task method defines a Rake task that generates a version file for the gem.
This method creates a task named :version that writes version information to a Ruby file in the lib directory. The generated file contains constants for the version and its components, as well as an optional epilogue section. The task ensures the target directory exists and uses secure file writing to prevent permission issues.
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
# File 'lib/gem_hadar.rb', line 804 def version_task desc m = "Writing version information for #{name}-#{version}" task :version do puts m mkdir_p dir = File.join('lib', path_name) secure_write(File.join(dir, 'version.rb')) do |v| v.puts <<~EOT #{module_type} #{path_module} # #{path_module} version VERSION = '#{version}' VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: VERSION_BUILD = VERSION_ARRAY[2] # :nodoc: end EOT version_epilogue.full? { |ve| v.puts ve } end end end |
#versions ⇒ Array<String>
The versions method retrieves and processes the list of git tags that match semantic versioning patterns.
It executes ‘git tag` to get all available tags, filters them using a regular expression to identify valid version strings, removes any ’v’ prefix from each version string, trims whitespace, and sorts the resulting array based on semantic versioning order.
order according to semantic versioning rules.
2053 2054 2055 2056 2057 2058 |
# File 'lib/gem_hadar.rb', line 2053 memoize method: def versions `git tag`.lines.grep(/^v?\d+\.\d+\.\d+$/).map(&:chomp).map { |tag| GemHadar::VersionSpec[tag, without_prefix: true] }.sort_by(&:version) end |
#write_gemfile ⇒ Object
The write_gemfile method creates and writes the default Gemfile content if it doesn’t exist. If a custom Gemfile exists, it only displays a warning.
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 |
# File 'lib/gem_hadar.rb', line 1920 def write_gemfile default_gemfile =<<~EOT # vim: set filetype=ruby et sw=2 ts=2: source 'https://rubygems.org' gemspec EOT current_gemfile = File.exist?('Gemfile') && File.read('Gemfile') case current_gemfile when false secure_write('Gemfile') do |output| output.write default_gemfile end when default_gemfile ;; else warn "INFO: Current Gemfile differs from default Gemfile." end end |
#write_ignore_file ⇒ Object
The write_ignore_file method writes the current ignore_files configuration to a .gitignore file in the project root directory.
1893 1894 1895 1896 1897 |
# File 'lib/gem_hadar.rb', line 1893 def write_ignore_file secure_write('.gitignore') do |output| output.puts(ignore.sort) end end |
#yard_dir ⇒ String
The yard_dir attribute accessor for configuring the output directory for YARD documentation.
This method sets up a DSL accessor for the yard_dir attribute, which specifies the directory where YARD documentation will be generated. It defaults to ‘doc’ and provides a way to customize the documentation output location through the configuration block.
450 451 452 |
# File 'lib/gem_hadar.rb', line 450 dsl_accessor :yard_dir do 'doc' end |
#yard_doc_task ⇒ Object
The yard_doc_task method configures and sets up a YARD documentation generation task.
This method initializes a YARD::Rake::YardocTask that processes Ruby source files and generates comprehensive documentation including private and protected methods. It configures the output directory, handles README files, includes additional documentation files, and sets up a pre-execution cleanup routine.
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 |
# File 'lib/gem_hadar.rb', line 1522 def yard_doc_task YARD::Rake::YardocTask.new(:yard_doc) do |t| t.files = doc_code_files.grep(%r(\.rb\z)) output_dir = yard_dir t. = [ "--output-dir=#{output_dir}" ] # Include private & protected methods in documentation t. << '--private' << '--protected' # Handle readme if present if readme && File.exist?(readme) t. << "--readme=#{readme}" end # Add additional documentation files if doc_files&.any? t.files.concat(doc_files.flatten) end # Add before hook for cleaning t.before = proc { clean output_dir puts "Generating full documentation in #{output_dir}..." } end end |
#yard_task ⇒ Object
The yard_task method sets up and registers Rake tasks for generating and managing YARD documentation.
It creates multiple subtasks under the :yard namespace, including tasks for creating private documentation, viewing the generated documentation, cleaning up documentation files, and listing undocumented elements. If YARD is not available, the method returns early without defining any tasks.
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 |
# File 'lib/gem_hadar.rb', line 1557 def yard_task defined? YARD or return yard_doc_task desc 'Create yard documentation (including private)' task :doc => :yard_doc namespace :yard do my_yard_dir = Pathname.new(yard_dir) task :private => :yard_doc task :public => :yard_doc desc 'Create yard documentation' task :doc => :yard_doc desc 'View the yard documentation' task :view do index_file = my_yard_dir + 'index.html' File.exist?(index_file) sh "open #{index_file}" end desc 'Clean the yard documentation' task :clean do rm_rf my_yard_dir end desc 'List all undocumented classes/modules/methods' task :'list-undoc' do sh "yard stats --list-undoc" end end desc 'Create the yard documentation and view it' task :yard => %i[ yard:private yard:view ] end |