Sha256: f2496b72071e23570aae6331bc143d6bbfec995a277db5096614adaf2b63186d

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require 'logger'
require 'fileutils'
require_relative 'background/base'
require_relative 'validation/base'

module Entangler
  module Executor
    class Base
      include Entangler::Executor::Background::Base
      include Entangler::Executor::Validation::Base

      GIT_IGNORE_REGEX = %r{^\.git(?:/[^/]+)*$}.freeze
      ENTANGLER_IGNORE_REGEX = /^\.entangler.*/.freeze

      attr_reader :base_dir

      def initialize(base_dir, opts = {})
        validate_base_dir(base_dir)
        @base_dir = File.realpath(File.expand_path(base_dir))
        @recently_received_paths = []
        @listener_pauses = [false, false]
        @opts = opts
        @opts[:ignore] = [GIT_IGNORE_REGEX] unless @opts.key?(:ignore)
        @opts[:ignore] << ENTANGLER_IGNORE_REGEX
        @opts[:force_polling] ||= false

        validate_opts
        Entangler::Logger.create_log_dir(base_dir)
      end

      def generate_abs_path(rel_path)
        File.join(base_dir, rel_path)
      end

      def strip_base_path(path, base_dir = self.base_dir)
        File.expand_path(path).sub(base_dir, '')
      end

      def run
        logger.info("Entangler v#{Entangler::VERSION}")
        start_listener
        start_remote_io
        Signal.trap('INT') { kill_off_threads }
        logger.info('Ready!')
        wait_for_threads
      ensure
        stop_listener
        logger.info('Stopping Entangler')
      end

      protected

      def send_to_remote(msg = {})
        Marshal.dump(msg, @remote_writer)
      end

      def logger
        @logger ||= Entangler::Logger.new(log_outputs, verbose: @opts[:verbose])
      end

      private

      def log_outputs
        [Entangler::Logger.log_file_path(base_dir)]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
entangler-1.6.1 lib/entangler/executor/base.rb
entangler-1.6.0 lib/entangler/executor/base.rb
entangler-1.5.1 lib/entangler/executor/base.rb
entangler-1.5.0 lib/entangler/executor/base.rb
entangler-1.4.1 lib/entangler/executor/base.rb
entangler-1.4.0 lib/entangler/executor/base.rb