Class: GitHubChangelogGenerator::Options

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/github_changelog_generator/options.rb

Overview

This class wraps Options, and knows a list of known options. Others options will raise exceptions.

Constant Summary collapse

UnsupportedOptionError =

Raised on initializing with unknown keys in the values hash, and when trying to store a value on an unknown key.

Class.new(ArgumentError)
KNOWN_OPTIONS =

List of valid option names

%i[
  add_issues_wo_labels
  add_pr_wo_labels
  add_sections
  author
  base
  between_tags
  breaking_labels
  breaking_prefix
  bug_labels
  bug_prefix
  cache_file
  cache_log
  config_file
  compare_link
  configure_sections
  date_format
  deprecated_labels
  deprecated_prefix
  due_tag
  enhancement_labels
  enhancement_prefix
  exclude_labels
  exclude_tags
  exclude_tags_regex
  filter_issues_by_milestone
  issues_of_open_milestones
  frontmatter
  future_release
  github_endpoint
  github_site
  header
  http_cache
  include_labels
  include_tags_regex
  issue_prefix
  issue_line_labels
  issue_line_body
  issues
  max_issues
  merge_prefix
  output
  project
  pulls
  release_branch
  release_url
  removed_labels
  removed_prefix
  require
  security_labels
  security_prefix
  simple_list
  since_tag
  since_commit
  ssl_ca_file
  summary_labels
  summary_prefix
  token
  unreleased
  unreleased_label
  unreleased_only
  user
  usernames_as_github_logins
  verbose
]

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Options

Returns a new instance of Options.

Parameters:

  • values (Hash)

Raises:



84
85
86
87
# File 'lib/github_changelog_generator/options.rb', line 84

def initialize(values)
  super(values)
  unsupported_options.any? && raise(UnsupportedOptionError, unsupported_options.inspect)
end

Instance Method Details

#[]=(key, val) ⇒ Object

Set option key to val.

Parameters:

  • key (Symbol)
  • val (Object)

Raises:



95
96
97
98
# 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?Boolean

Boolean method for whether the user is using add_sections

Returns:

  • (Boolean)


129
130
131
# File 'lib/github_changelog_generator/options.rb', line 129

def add_sections?
  !self[:add_sections].nil? && !self[:add_sections].empty?
end

#configure_sections?Boolean

Boolean method for whether the user is using configure_sections

Returns:

  • (Boolean)


124
125
126
# File 'lib/github_changelog_generator/options.rb', line 124

def configure_sections?
  !self[:configure_sections].nil? && !self[:configure_sections].empty?
end

#load_custom_ruby_filesObject

Loads the configured Ruby files from the –require option.



106
107
108
# 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.



111
112
113
114
115
116
117
118
119
120
121
# 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

#to_hashHash

Returns:

  • (Hash)


101
102
103
# File 'lib/github_changelog_generator/options.rb', line 101

def to_hash
  values
end

#write_to_file?Boolean

Returns whether write to ‘:output`.

Returns:

  • (Boolean)

    whether write to ‘:output`



134
135
136
# File 'lib/github_changelog_generator/options.rb', line 134

def write_to_file?
  self[:output].present?
end