3
3
module GitHubChangelogGenerator
4
4
ParserError = Class . new ( StandardError )
5
5
6
+ # ParserFile is a configuration file reader which sets options in the
7
+ # given Hash.
8
+ #
9
+ # In your project's root, you can put a file named
10
+ # <tt>.github_changelog_generator</tt> to override defaults:
11
+ #
12
+ # Example:
13
+ # header_label=# My Super Changelog
14
+ # future-release=5.0.0
15
+ # since-tag=1.0.0
16
+ #
17
+ # The configuration format is <tt>some-key=value</tt> or <tt>some_key=value</tt>.
18
+ #
6
19
class ParserFile
7
- FILENAME = ".github_changelog_generator"
8
-
9
- # @param options [Hash]
10
- # @param file [nil,IO]
20
+ # @param options [Hash] options to be configured from file contents
21
+ # @param file [nil,IO] configuration file handle, defaults to opening `.github_changelog_generator`
11
22
def initialize ( options , file = read_default_file )
12
23
@options = options
13
24
@file = file
14
25
end
15
26
16
- def read_default_file
17
- path = Pathname ( File . expand_path ( FILENAME ) )
18
- File . open ( path ) if path . exist?
19
- end
20
-
21
- # Set @options using configuration file lines.
27
+ # Sets options using configuration file content
22
28
def parse!
23
29
return unless @file
24
30
@file . each_with_index { |line , i | parse_line! ( line , i + 1 ) }
@@ -27,6 +33,13 @@ def parse!
27
33
28
34
private
29
35
36
+ FILENAME = ".github_changelog_generator"
37
+
38
+ def read_default_file
39
+ path = Pathname ( File . expand_path ( FILENAME ) )
40
+ File . open ( path ) if path . exist?
41
+ end
42
+
30
43
def parse_line! ( line , line_number )
31
44
option_name , value = extract_pair ( line )
32
45
@options [ option_key_for ( option_name ) ] = convert_value ( value , option_name )
0 commit comments