class Semverve::Configuration
Mutable configuration used before Semverve resolves project defaults.
Constants
- DEFAULT_VERSION_CODE_REFERENCE_PATTERN
-
Default Ruby pattern for code version literals that are safe to rewrite.
@return [Regexp]
- VALID_RELEASE_CHECKS
-
Release-readiness surfaces supported by release check tasks.
@return [Array<Symbol>]
- VALID_VERSION_CHECKS
-
Version-maintenance surfaces supported by umbrella check and fix tasks.
@return [Array<Symbol>]
Attributes
Whether increments should run +bundle lock+ after writing a version.
@return [Boolean]
Callable used to run shell commands such as +bundle lock+.
@return [#call]
Version-file format to read, replace, or generate.
@return [Symbol, String]
Explicit gem name to use instead of inferring one from the project.
@return [String, nil]
Explicit Ruby module name to use in generated version files.
@return [String, nil]
Framework preset used to apply project defaults.
@return [Symbol, String, nil]
Release-readiness surfaces run by the release check task.
@return [Array<Symbol, String>]
Project root used when inferring metadata and expanding paths.
@return [String, nil]
RubyGems-compatible host used for published-version checks.
@return [String]
Version-maintenance surfaces run by the umbrella check and fix tasks.
@return [Array<Symbol, String>]
Code files to scan for safe version literals.
@return [Rake::FileList]
Pattern used to find safe version literals in code files.
@return [Regexp]
Documentation files to scan for version references.
@return [Rake::FileList]
Explicit version-file path relative to the project root.
@return [String, nil]
Version-reference comparison mode.
@return [Symbol, String]
Public Class Methods
Source
# File lib/semverve/configuration.rb, line 125 def initialize @explicit_attributes = [] @bundle_lock = false @command_runner = ->(command) { system(command) } @format = :module @preset = nil @rubygems_host = "https://rubygems.org" @version_code_reference_files = Rake::FileList[] self.version_code_reference_pattern = DEFAULT_VERSION_CODE_REFERENCE_PATTERN @version_doc_reference_files = Rake::FileList["README*", "**/README*"].exclude( ".git/**/*", "coverage/**/*", "tmp/**/*", "vendor/**/*" ) @version_reference_mode = :older self.release_checks = [] self.version_checks = VALID_VERSION_CHECKS end
Initializes configuration with Semverveโs default settings.
@return [Semverve::Configuration]
Public Instance Methods
Source
# File lib/semverve/configuration.rb, line 266 def expanded_root File.expand_path(resolved_value(:root) || Dir.pwd) end
Absolute project root.
@return [String]
Source
# File lib/semverve/configuration.rb, line 176 def format=(format) set_explicit(:format, format) end
Sets the version-file format.
@param [Symbol, String] format
@return [Symbol, String]
Source
# File lib/semverve/configuration.rb, line 186 def gem_name=(gem_name) set_explicit(:gem_name, gem_name) end
Source
# File lib/semverve/configuration.rb, line 196 def module_name=(module_name) set_explicit(:module_name, module_name) end
Sets the module name used for generated version files.
@param [String, nil] module_name
@return [String, nil]
# File lib/semverve/configuration.rb, line 339 def normalize_release_checks(checks) normalized_checks = Array(checks).map do |check| check.respond_to?(:to_sym) ? check.to_sym : check end return normalized_checks if normalized_checks.all? { |check| VALID_RELEASE_CHECKS.include?(check) } invalid_checks = normalized_checks.reject { |check| VALID_RELEASE_CHECKS.include?(check) } raise Error, "Unknown release check #{invalid_checks.map(&:inspect).join(", ")}. Use :rubygems." end
Normalizes and validates release checks.
@param [Array<Symbol, String>] checks
@return [Array<Symbol>]
# File lib/semverve/configuration.rb, line 321 def normalize_version_checks(checks) normalized_checks = Array(checks).map do |check| check.respond_to?(:to_sym) ? check.to_sym : check end return normalized_checks if normalized_checks.all? { |check| VALID_VERSION_CHECKS.include?(check) } invalid_checks = normalized_checks.reject { |check| VALID_VERSION_CHECKS.include?(check) } valid_check_names = VALID_VERSION_CHECKS.map(&:inspect) valid_checks = "#{valid_check_names[0...-1].join(", ")}, or #{valid_check_names.last}" raise Error, "Unknown version check #{invalid_checks.map(&:inspect).join(", ")}. Use #{valid_checks}." end
Normalizes and validates umbrella version checks.
@param [Array<Symbol, String>] checks
@return [Array<Symbol>]
Source
# File lib/semverve/configuration.rb, line 274 def normalized_format resolved_value(:format).to_sym end
Configured format normalized for lookup.
@return [Symbol]
Source
# File lib/semverve/configuration.rb, line 282 def normalized_release_checks normalize_release_checks(release_checks) end
Configured release checks normalized for lookup.
@return [Array<Symbol>]
Source
# File lib/semverve/configuration.rb, line 303 def normalized_version_checks normalize_version_checks(version_checks) end
Configured version checks normalized for lookup.
@return [Array<Symbol>]
# File lib/semverve/configuration.rb, line 311 def normalized_version_reference_mode version_reference_mode.to_sym end
Configured version-reference mode normalized for lookup.
@return [Symbol]
Source
# File lib/semverve/configuration.rb, line 206 def preset=(preset) @preset_defaults = nil @preset = preset.nil? ? nil : Presets.fetch(preset).name end
Sets the framework preset used for project defaults.
@param [Symbol, String, nil] preset
@return [Symbol, nil]
Source
# File lib/semverve/configuration.rb, line 217 def release_checks=(checks) @release_checks = normalize_release_checks(checks) end
Sets the release-readiness surfaces run by the release check task.
@param [Array<Symbol, String>] checks
@return [Array<Symbol>]
Source
# File lib/semverve/configuration.rb, line 149 def resolved metadata = ProjectMetadata.new(self) ResolvedConfiguration.new( bundle_lock: bundle_lock, command_runner: command_runner, format: normalized_format, gem_name: metadata.gem_name, module_name: metadata.module_name, release_checks: normalized_release_checks, root: expanded_root, rubygems_host: rubygems_host, version_file: metadata.version_file, version_checks: normalized_version_checks, version_code_reference_files: version_code_reference_files, version_code_reference_pattern: version_code_reference_pattern, version_doc_reference_files: version_doc_reference_files, version_reference_mode: normalized_version_reference_mode ) end
Resolves explicit configuration and inferred project metadata.
@return [Semverve::ResolvedConfiguration]
Source
# File lib/semverve/configuration.rb, line 292 def resolved_value(attribute) return public_send(attribute) if explicit_attribute?(attribute) return preset_defaults[attribute] if preset_defaults.key?(attribute) public_send(attribute) end
Resolved value for a configurable attribute before metadata inference.
@param [Symbol] attribute
@return [Object]
Source
# File lib/semverve/configuration.rb, line 227 def root=(root) set_explicit(:root, root) end
Sets the project root used when expanding paths.
@param [String, nil] root
@return [String, nil]
# File lib/semverve/configuration.rb, line 355 def validate_version_code_reference_pattern(pattern) unless pattern.is_a?(Regexp) raise Error, "version_code_reference_pattern must be a Regexp." end unless pattern.named_captures.key?("version") raise Error, "version_code_reference_pattern must include a named capture called version." end end
Validates the configured code reference pattern.
@param [Object] pattern
@return [void]
Source
# File lib/semverve/configuration.rb, line 258 def version_checks=(checks) @version_checks = normalize_version_checks(checks) end
Sets the version-maintenance surfaces run by umbrella tasks.
@param [Array<Symbol, String>] checks
@return [Array<Symbol>]
# File lib/semverve/configuration.rb, line 247 def version_code_reference_pattern=(pattern) validate_version_code_reference_pattern(pattern) @version_code_reference_pattern = pattern end
Sets the pattern used to find safe version literals in code files.
@param [Regexp] pattern
@return [Regexp]
Source
# File lib/semverve/configuration.rb, line 237 def version_file=(version_file) set_explicit(:version_file, version_file) end
Sets the version-file path relative to the project root.
@param [String, nil] version_file
@return [String, nil]