Sha256: 7a258c2f4e5e5faeab55d4955199f9fb5e4f04114fe455a2614eb027fab21089

Contents?: true

Size: 721 Bytes

Versions: 4

Compression:

Stored size: 721 Bytes

Contents

# frozen_string_literal: true

module Codeowners
  class Checker
    # Convert CODEOWNERS file content to an array.
    class FileAsArray
      def initialize(file)
        @file = file
        @target_dir, = File.split(@file)
      end

      # @return <Array> of lines chomped
      def content
        @content ||= File.readlines(@file).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

        Dir.mkdir(@target_dir) unless Dir.exist?(@target_dir)

        File.open(@file, 'w+') do |f|
          f.puts content
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
codeowners-checker-1.0.4 lib/codeowners/checker/file_as_array.rb
codeowners-checker-1.0.3 lib/codeowners/checker/file_as_array.rb
codeowners-checker-1.0.2 lib/codeowners/checker/file_as_array.rb
codeowners-checker-1.0.1 lib/codeowners/checker/file_as_array.rb