Sha256: fe46132880db7d11f49d983d18fbd0e92df248ea2ad72786084e5f972efcc98f

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'rake/file_list'
require 'open3'

module EatYourVegetables
  module Tools
    class Base
      def initialize(parent_branch:)
        @parent_branch = parent_branch
        @ambition_filter = []
      end

      def filter(file)
        if file.is_a? Array
          file.each do |f|
            filter f
          end
        end

        @ambition_filter << file
      end

      def step_difference
        return 0 unless is_configed?

        parent_exclusions = excluded_files(parent_file_contents)
        current_exclusions = excluded_files(current_file_contents)

        (parent_exclusions - current_exclusions).count
      end

      def parent_file_contents
        cmdstr = "git show origin/master:#{config_file}"
        stdout, stderr, status = Open3.capture3(cmdstr)

        stdout
      end

      def current_file_contents
        File.read(config_file)
      end

      def is_configed?
        File.file?(config_file) && !parent_file_contents.empty?
      rescue Errno::ENOENT
        false
      end

      protected

      def config_file
        raise NotImplementedError
      end

      def excluded_files(_content)
        raise NotImplementedError
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eat_your_vegetables-0.1.1 lib/eat_your_vegetables/tools/base.rb