Class: Semverve::Configuration
- Inherits:
-
Object
- Object
- Semverve::Configuration
- Defined in:
- lib/semverve/configuration.rb
Overview
Mutable configuration used before Semverve resolves project defaults.
Constant Summary collapse
- VALID_VERSION_CHECKS =
Version-maintenance surfaces supported by umbrella check and fix tasks.
[:doc_references, :code_references, :metadata].freeze
- DEFAULT_VERSION_CODE_REFERENCE_PATTERN =
Default Ruby pattern for code version literals that are safe to rewrite.
/^\s*(?:(?:[A-Z]\w*::)*(?:[A-Z]\w*VERSION[A-Z0-9_]*|VERSION)|(?:[a-z_]\w*|self)\.version)\s*=\s*(?<quote>["'])(?<version>\d+\.\d+\.\d+)\k<quote>/
Instance Attribute Summary collapse
-
#bundle_lock ⇒ Boolean
Whether increments should run
bundle lockafter writing a version. -
#command_runner ⇒ #call
Callable used to run shell commands such as
bundle lock. -
#format ⇒ Symbol, String
Version-file format to read, replace, or generate.
-
#gem_name ⇒ String?
Explicit gem name to use instead of inferring one from the project.
-
#module_name ⇒ String?
Explicit Ruby module name to use in generated version files.
-
#preset ⇒ Symbol, ...
Framework preset used to apply project defaults.
-
#root ⇒ String?
Project root used when inferring metadata and expanding paths.
-
#version_checks ⇒ Array<Symbol, String>
Version-maintenance surfaces run by the umbrella check and fix tasks.
-
#version_code_reference_files ⇒ Rake::FileList
Code files to scan for safe version literals.
-
#version_code_reference_pattern ⇒ Regexp
Pattern used to find safe version literals in code files.
-
#version_doc_reference_files ⇒ Rake::FileList
Documentation files to scan for version references.
-
#version_file ⇒ String?
Explicit version-file path relative to the project root.
-
#version_reference_mode ⇒ Symbol, String
Version-reference comparison mode.
Instance Method Summary collapse
-
#expanded_root ⇒ String
Absolute project root.
-
#initialize ⇒ Semverve::Configuration
constructor
Initializes configuration with Semverve's default settings.
-
#normalize_version_checks(checks) ⇒ Array<Symbol>
Normalizes and validates umbrella version checks.
-
#normalized_format ⇒ Symbol
Configured format normalized for lookup.
-
#normalized_version_checks ⇒ Array<Symbol>
Configured version checks normalized for lookup.
-
#normalized_version_reference_mode ⇒ Symbol
Configured version-reference mode normalized for lookup.
-
#resolved ⇒ Semverve::ResolvedConfiguration
Resolves explicit configuration and inferred project metadata.
-
#resolved_value(attribute) ⇒ Object
Resolved value for a configurable attribute before metadata inference.
-
#validate_version_code_reference_pattern(pattern) ⇒ void
Validates the configured code reference pattern.
Constructor Details
#initialize ⇒ Semverve::Configuration
Initializes configuration with Semverve's default settings.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/semverve/configuration.rb', line 107 def initialize @explicit_attributes = [] @bundle_lock = false @command_runner = ->(command) { system(command) } @format = :module @preset = nil @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.version_checks = VALID_VERSION_CHECKS end |
Instance Attribute Details
#bundle_lock ⇒ Boolean
Whether increments should run bundle lock after writing a version.
29 30 31 |
# File 'lib/semverve/configuration.rb', line 29 def bundle_lock @bundle_lock end |
#command_runner ⇒ #call
Callable used to run shell commands such as bundle lock.
35 36 37 |
# File 'lib/semverve/configuration.rb', line 35 def command_runner @command_runner end |
#format ⇒ Symbol, String
Version-file format to read, replace, or generate.
41 42 43 |
# File 'lib/semverve/configuration.rb', line 41 def format @format end |
#gem_name ⇒ String?
Explicit gem name to use instead of inferring one from the project.
47 48 49 |
# File 'lib/semverve/configuration.rb', line 47 def gem_name @gem_name end |
#module_name ⇒ String?
Explicit Ruby module name to use in generated version files.
53 54 55 |
# File 'lib/semverve/configuration.rb', line 53 def module_name @module_name end |
#preset ⇒ Symbol, ...
Framework preset used to apply project defaults.
59 60 61 |
# File 'lib/semverve/configuration.rb', line 59 def preset @preset end |
#root ⇒ String?
Project root used when inferring metadata and expanding paths.
65 66 67 |
# File 'lib/semverve/configuration.rb', line 65 def root @root end |
#version_checks ⇒ Array<Symbol, String>
Version-maintenance surfaces run by the umbrella check and fix tasks.
95 96 97 |
# File 'lib/semverve/configuration.rb', line 95 def version_checks @version_checks end |
#version_code_reference_files ⇒ Rake::FileList
Code files to scan for safe version literals.
77 78 79 |
# File 'lib/semverve/configuration.rb', line 77 def version_code_reference_files @version_code_reference_files end |
#version_code_reference_pattern ⇒ Regexp
Pattern used to find safe version literals in code files.
83 84 85 |
# File 'lib/semverve/configuration.rb', line 83 def version_code_reference_pattern @version_code_reference_pattern end |
#version_doc_reference_files ⇒ Rake::FileList
Documentation files to scan for version references.
89 90 91 |
# File 'lib/semverve/configuration.rb', line 89 def version_doc_reference_files @version_doc_reference_files end |
#version_file ⇒ String?
Explicit version-file path relative to the project root.
71 72 73 |
# File 'lib/semverve/configuration.rb', line 71 def version_file @version_file end |
#version_reference_mode ⇒ Symbol, String
Version-reference comparison mode.
101 102 103 |
# File 'lib/semverve/configuration.rb', line 101 def version_reference_mode @version_reference_mode end |
Instance Method Details
#expanded_root ⇒ String
Absolute project root.
234 235 236 |
# File 'lib/semverve/configuration.rb', line 234 def File.(resolved_value(:root) || Dir.pwd) end |
#normalize_version_checks(checks) ⇒ Array<Symbol>
Normalizes and validates umbrella version checks.
281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/semverve/configuration.rb', line 281 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 |
#normalized_format ⇒ Symbol
Configured format normalized for lookup.
242 243 244 |
# File 'lib/semverve/configuration.rb', line 242 def normalized_format resolved_value(:format).to_sym end |
#normalized_version_checks ⇒ Array<Symbol>
Configured version checks normalized for lookup.
263 264 265 |
# File 'lib/semverve/configuration.rb', line 263 def normalized_version_checks normalize_version_checks(version_checks) end |
#normalized_version_reference_mode ⇒ Symbol
Configured version-reference mode normalized for lookup.
271 272 273 |
# File 'lib/semverve/configuration.rb', line 271 def normalized_version_reference_mode version_reference_mode.to_sym end |
#resolved ⇒ Semverve::ResolvedConfiguration
Resolves explicit configuration and inferred project metadata.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/semverve/configuration.rb', line 129 def resolved = ProjectMetadata.new(self) ResolvedConfiguration.new( bundle_lock: bundle_lock, command_runner: command_runner, format: normalized_format, gem_name: .gem_name, module_name: .module_name, root: , version_file: .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 |
#resolved_value(attribute) ⇒ Object
Resolved value for a configurable attribute before metadata inference.
252 253 254 255 256 257 |
# File 'lib/semverve/configuration.rb', line 252 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 |
#validate_version_code_reference_pattern(pattern) ⇒ void
This method returns an undefined value.
Validates the configured code reference pattern.
299 300 301 302 303 304 305 306 307 |
# File 'lib/semverve/configuration.rb', line 299 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 |