From 179f110b8a26294584d782ef6c07163cde8d0a8c Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 23 Feb 2016 23:46:23 +0100 Subject: [PATCH 1/2] Pathnames to iterate over lines, check existence --- lib/github_changelog_generator/parser_file.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index 38cc54d..c961bef 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -1,3 +1,5 @@ +require 'pathname' + module GitHubChangelogGenerator ParserError = Class.new(StandardError) @@ -7,15 +9,15 @@ module GitHubChangelogGenerator end def parse! - return unless File.exist?(file) + return unless file.exist? - File.readlines(file).each { |line| parse_line!(line) } + file.each_line { |line| parse_line!(line) } end private def file - @file ||= File.expand_path(@options[:params_file] || ".github_changelog_generator") + @file ||= Pathname(File.expand_path(@options[:params_file] || ".github_changelog_generator")) end def parse_line!(line) From 4e6906dccfccf40f2f432bf3708e98eb0ee95370 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Tue, 23 Feb 2016 23:54:20 +0100 Subject: [PATCH 2/2] Add default options filename as constant --- lib/github_changelog_generator/parser_file.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index c961bef..5100e18 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -4,20 +4,21 @@ module GitHubChangelogGenerator ParserError = Class.new(StandardError) class ParserFile + FILENAME = ".github_changelog_generator" + def initialize(options) @options = options end + # Destructively change @options using data in configured options file. def parse! - return unless file.exist? - - file.each_line { |line| parse_line!(line) } + file.each_line { |line| parse_line!(line) } if file.exist? end private def file - @file ||= Pathname(File.expand_path(@options[:params_file] || ".github_changelog_generator")) + @file ||= Pathname(File.expand_path(@options[:params_file] || FILENAME)) end def parse_line!(line)