Sha256: 31204c9a886a9aab1a082632ea72ba48636074f0a88efe746008b927c1db7447

Contents?: true

Size: 1.86 KB

Versions: 96

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require 'listen/file'
require 'listen/directory'

module Listen
  # TODO: rename to Snapshot
  class Change
    # TODO: test this class for coverage
    class Config
      def initialize(queue, silencer)
        @queue = queue
        @silencer = silencer
      end

      def silenced?(path, type)
        @silencer.silenced?(Pathname(path), type)
      end

      def queue(*args)
        @queue << args
      end
    end

    attr_reader :record

    def initialize(config, record)
      @config = config
      @record = record
    end

    # Invalidate some part of the snapshot/record (dir, file, subtree, etc.)
    # rubocop:disable Metrics/MethodLength
    # rubocop:disable Metrics/CyclomaticComplexity
    # rubocop:disable Metrics/PerceivedComplexity
    def invalidate(type, rel_path, options)
      watched_dir = Pathname.new(record.root)

      change = options[:change]
      cookie = options[:cookie]

      if !cookie && @config.silenced?(rel_path, type)
        Listen.logger.debug { "(silenced): #{rel_path.inspect}" }
        return
      end

      path = watched_dir + rel_path

      Listen.logger.debug do
        log_details = options[:silence] && 'recording' || change || 'unknown'
        "#{log_details}: #{type}:#{path} (#{options.inspect})"
      end

      if change
        options = cookie ? { cookie: cookie } : {}
        @config.queue(type, change, watched_dir, rel_path, options)
      elsif type == :dir
        # NOTE: POSSIBLE RECURSION
        # TODO: fix - use a queue instead
        Directory.scan(self, rel_path, options)
      elsif (change = File.change(record, rel_path)) && !options[:silence]
        @config.queue(:file, change, watched_dir, rel_path)
      end
    end
    # rubocop:enable Metrics/MethodLength
    # rubocop:enable Metrics/CyclomaticComplexity
    # rubocop:enable Metrics/PerceivedComplexity
  end
end

Version data entries

96 entries across 95 versions & 6 rubygems

Version Path
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
listen-3.9.0 lib/listen/change.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/change.rb