class GitHubChangelogGenerator::Options
This class wraps Options
, and knows a list of known options. Others options will raise exceptions.
Constants
- KNOWN_OPTIONS
List of valid option names
- UnsupportedOptionError
Raised on initializing with unknown keys in the values hash, and when trying to store a value on an unknown key.
Public Class Methods
@param values [Hash]
@raise [UnsupportedOptionError] if given values contain unknown options
# File lib/github_changelog_generator/options.rb, line 84 def initialize(values) super(values) unsupported_options.any? && raise(UnsupportedOptionError, unsupported_options.inspect) end
Public Instance Methods
Set option key to val.
@param key [Symbol] @param val [Object]
@raise [UnsupportedOptionError] when trying to set an unknown option
# File lib/github_changelog_generator/options.rb, line 95 def []=(key, val) supported_option?(key) || raise(UnsupportedOptionError, key.inspect) values[key] = val end
Boolean method for whether the user is using add_sections
# File lib/github_changelog_generator/options.rb, line 129 def add_sections? !self[:add_sections].nil? && !self[:add_sections].empty? end
Boolean method for whether the user is using configure_sections
# File lib/github_changelog_generator/options.rb, line 124 def configure_sections? !self[:configure_sections].nil? && !self[:configure_sections].empty? end
Loads the configured Ruby files from the –require option.
# File lib/github_changelog_generator/options.rb, line 106 def load_custom_ruby_files self[:require].each { |f| require f } end
Pretty-prints a censored options hash, if :verbose.
# File lib/github_changelog_generator/options.rb, line 111 def print_options return unless self[:verbose] Helper.log.info "Using these options:" # For ruby 2.5.0+ censored_values.each do |key, value| print(key.inspect, "=>", value.inspect) puts "" end puts "" end
@return [Hash]
# File lib/github_changelog_generator/options.rb, line 101 def to_hash values end
@return [Boolean] whether write to `:output`
# File lib/github_changelog_generator/options.rb, line 134 def write_to_file? self[:output].present? end
Private Instance Methods
Returns a censored options hash.
@return [Hash] The GitHub `:token` key is censored in the output.
# File lib/github_changelog_generator/options.rb, line 147 def censored_values values.clone.tap { |opts| opts[:token] = opts[:token].nil? ? "No token used" : "hidden value" } end
# File lib/github_changelog_generator/options.rb, line 155 def supported_option?(key) KNOWN_OPTIONS.include?(key) end
# File lib/github_changelog_generator/options.rb, line 151 def unsupported_options values.keys - KNOWN_OPTIONS end
# File lib/github_changelog_generator/options.rb, line 140 def values __getobj__ end