Module: FileUtils
- Defined in:
- lib/nub/fileutils.rb
Overview
Monkey patch FileUtils with some useful methods
Instance Method Summary collapse
-
#update_copyright(path, copyright, year) ⇒ Object
Check copyright and update if required.
Instance Method Details
#update_copyright(path, copyright, year) ⇒ Object
Check copyright and update if required
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nub/fileutils.rb', line 30 def update_copyright(path, copyright, year) modify(path){|line| if line =~ /##{Regexp.quote(copyright)}/ year = line[/##{Regexp.quote(copyright)}\s+((\d{4}\s)|(\d{4}-\d{4})).*/, 1].strip if year.include?("-") years = year.split("-") line.gsub!(year, "#{years.first}-#{curr_year}") if years.last != curr_year else prev_year = year == curr_year.to_s ? year.to_i - 1 : year line.gsub!(year.to_s, "#{prev_year}-#{curr_year}") end end } end |