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

new(values) click to toggle source

@param values [Hash]

@raise [UnsupportedOptionError] if given values contain unknown options

Calls superclass method
# 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

[]=(key, val) click to toggle source

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
add_sections?() click to toggle source

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
configure_sections?() click to toggle source

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
load_custom_ruby_files() click to toggle source

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
print_options() click to toggle source

Pretty-prints a censored options hash, if :verbose.

to_hash() click to toggle source

@return [Hash]

# File lib/github_changelog_generator/options.rb, line 101
def to_hash
  values
end
write_to_file?() click to toggle source

@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

censored_values() click to toggle source

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
supported_option?(key) click to toggle source
# File lib/github_changelog_generator/options.rb, line 155
def supported_option?(key)
  KNOWN_OPTIONS.include?(key)
end
unsupported_options() click to toggle source
# File lib/github_changelog_generator/options.rb, line 151
def unsupported_options
  values.keys - KNOWN_OPTIONS
end
values() click to toggle source
# File lib/github_changelog_generator/options.rb, line 140
def values
  __getobj__
end