Class: Codeowners::Checker::FileAsArray
- Inherits:
-
Object
- Object
- Codeowners::Checker::FileAsArray
- Defined in:
- lib/codeowners/checker/file_as_array.rb
Overview
Convert CODEOWNERS file content to an array.
Instance Attribute Summary collapse
-
#content ⇒ Array
Of lines chomped.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename) ⇒ FileAsArray
constructor
A new instance of FileAsArray.
-
#persist! ⇒ Object
Save content to the @file Creates the directory of the file if needed.
Constructor Details
#initialize(filename) ⇒ FileAsArray
Returns a new instance of FileAsArray.
10 11 12 13 |
# File 'lib/codeowners/checker/file_as_array.rb', line 10 def initialize(filename) @filename = filename @target_dir, = File.split(@filename) end |
Instance Attribute Details
#content ⇒ Array
Returns of lines chomped.
16 17 18 19 20 |
# File 'lib/codeowners/checker/file_as_array.rb', line 16 def content @content ||= File.readlines(@filename).map(&:chomp) rescue Errno::ENOENT @content = [] end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
8 9 10 |
# File 'lib/codeowners/checker/file_as_array.rb', line 8 def filename @filename end |
Instance Method Details
#persist! ⇒ Object
Save content to the @file Creates the directory of the file if needed
24 25 26 27 28 29 30 |
# File 'lib/codeowners/checker/file_as_array.rb', line 24 def persist! Dir.mkdir(@target_dir) unless Dir.exist?(@target_dir) File.open(@filename, 'w+') do |f| f.puts content end end |