lib/codeowners/checker/file_as_array.rb in codeowners-checker-1.0.4 vs lib/codeowners/checker/file_as_array.rb in codeowners-checker-1.0.5
- old
+ new
@@ -2,29 +2,30 @@
module Codeowners
class Checker
# Convert CODEOWNERS file content to an array.
class FileAsArray
- def initialize(file)
- @file = file
- @target_dir, = File.split(@file)
+ attr_writer :content
+ attr_reader :filename
+
+ def initialize(filename)
+ @filename = filename
+ @target_dir, = File.split(@filename)
end
# @return <Array> of lines chomped
def content
- @content ||= File.readlines(@file).map(&:chomp)
+ @content ||= File.readlines(@filename).map(&:chomp)
rescue Errno::ENOENT
@content = []
end
# Save content to the @file
# Creates the directory of the file if needed
- def content=(content)
- @content = content
-
+ def persist!
Dir.mkdir(@target_dir) unless Dir.exist?(@target_dir)
- File.open(@file, 'w+') do |f|
+ File.open(@filename, 'w+') do |f|
f.puts content
end
end
end
end