From 6b64d4e4a20e55be2d7b9bca70335d29f6310c11 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 19 Mar 2016 15:50:05 +0100 Subject: [PATCH] Docs --- lib/github_changelog_generator/parser_file.rb | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index c36b6ae..d71a71b 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -3,22 +3,28 @@ require "pathname" module GitHubChangelogGenerator ParserError = Class.new(StandardError) + # ParserFile is a configuration file reader which sets options in the + # given Hash. + # + # In your project's root, you can put a file named + # .github_changelog_generator to override defaults: + # + # Example: + # header_label=# My Super Changelog + # future-release=5.0.0 + # since-tag=1.0.0 + # + # The configuration format is some-key=value or some_key=value. + # class ParserFile - FILENAME = ".github_changelog_generator" - - # @param options [Hash] - # @param file [nil,IO] + # @param options [Hash] options to be configured from file contents + # @param file [nil,IO] configuration file handle, defaults to opening `.github_changelog_generator` def initialize(options, file = read_default_file) @options = options @file = file end - def read_default_file - path = Pathname(File.expand_path(FILENAME)) - File.open(path) if path.exist? - end - - # Set @options using configuration file lines. + # Sets options using configuration file content def parse! return unless @file @file.each_with_index { |line, i| parse_line!(line, i + 1) } @@ -27,6 +33,13 @@ module GitHubChangelogGenerator private + FILENAME = ".github_changelog_generator" + + def read_default_file + path = Pathname(File.expand_path(FILENAME)) + File.open(path) if path.exist? + end + def parse_line!(line, line_number) option_name, value = extract_pair(line) @options[option_key_for(option_name)] = convert_value(value, option_name)