Sha256: 1b1dd6fa70490a4a4a6cb459a9629e0cf67ce87289e2ec983f58c2407adec95f

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require_relative 'group'
require_relative 'array'

module Codeowners
  class Checker
    # Manage CODEOWNERS file reading and re-writing.
    class CodeOwners
      include Enumerable

      attr_reader :file_manager, :transform_line_procs

      def initialize(file_manager, transformers: nil)
        @file_manager = file_manager
        @transform_line_procs = [
          method(:build_line),
          *transformers
        ]
      end

      def persist!
        file_manager.content = to_content
      end

      def main_group
        @main_group ||= Group.parse(list)
      end

      def each(&block)
        main_group.each(&block)
      end

      def to_content
        main_group.to_content
      end

      private

      def list
        @list ||= @file_manager.content.yield_self do |list|
          transform_line_procs.each do |transform_line_proc|
            list = list.flat_map { |line| transform_line_proc.call(line) }.compact
          end
          list
        end
      end

      def build_line(line)
        Codeowners::Checker::Group::Line.build(line)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codeowners-checker-1.0.0 lib/codeowners/checker/code_owners.rb