Fixing issue with prepare method. The issue was that [stripped_contents.length..-1] was not capturing the trailing contents as expected. Instead it was grabbing the last 2 characters of my identifier block and then tacking those 2 characters back on to the end. In short, .length and the range operator are not behaving consistently on the input.

This commit is contained in:
Jeremy Lingmann 2011-03-10 21:49:38 -08:00
parent 1f11510d87
commit 7dd0a046ae

View File

@ -108,11 +108,15 @@ module Whenever
end
def prepare(contents)
# Some cron implementations require all non-comment lines to be newline-terminated.
# Preserve any whitespace at the end of contents. (issue #95)
stripped_contents = contents.strip
tail = contents[stripped_contents.length..-1]
stripped_contents.split("\n")[@options[:cut]..-1].join("\n") + tail
# Strip n lines from the top of the file as specified by the :cut option.
# Use split with a -1 limit option to ensure the join is able to rebuild
# the file with all of the original seperators in-tact.
stripped_contents = contents.split($/,-1)[@options[:cut]..-1].join($/)
# Some cron implementations require all non-comment lines to be newline-
# terminated. (issue #95) Strip all newlines and replace with the default
# platform record seperator ($/)
stripped_contents.gsub!(/\s+$/, $/)
end
def comment_base