Sha256: 914127e17552fb122d393a5fa519831409a099633e3255c50fd34783ad1bfc29

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

require 'thread'

require 'forwardable'

module Listen
  module Event
    class Queue
      class Config
        def initialize(relative)
          @relative = relative
        end

        def relative?
          @relative
        end
      end

      def initialize(config, &block)
        @event_queue = ::Queue.new
        @block = block
        @config = config
      end

      def <<(args)
        type, change, dir, path, options = *args
        fail "Invalid type: #{type.inspect}" unless [:dir, :file].include? type
        fail "Invalid change: #{change.inspect}" unless change.is_a?(Symbol)
        fail "Invalid path: #{path.inspect}" unless path.is_a?(String)

        dir = _safe_relative_from_cwd(dir)
        event_queue.public_send(:<<, [type, change, dir, path, options])

        block.call(args) if block
      end

      def empty?
        event_queue.empty?
      end

      def pop
        event_queue.pop
      end

      private

      attr_reader :event_queue
      attr_reader :block
      attr_reader :config

      def _safe_relative_from_cwd(dir)
        return dir unless config.relative?
        dir.relative_path_from(Pathname.pwd)
      rescue ArgumentError
        dir
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/listen-3.0.8/lib/listen/event/queue.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/listen-3.0.8/lib/listen/event/queue.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib/listen/event/queue.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib/listen/event/queue.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib/listen/event/queue.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib/listen/event/queue.rb
listen-3.0.8 lib/listen/event/queue.rb