Sha256: 02983c3479002d098644854541c1c4ac793e7eed14baab3f2a81d358eefcfcd1

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

require 'thread'

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

13 entries across 13 versions & 6 rubygems

Version Path
sass-listen-3.0.7 lib/listen/event/queue.rb
listen-3.0.7 lib/listen/event/queue.rb
listen-3.0.6 lib/listen/event/queue.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/listen-3.0.5/lib/listen/event/queue.rb
listen-3.0.5 lib/listen/event/queue.rb
listen-3.0.4 lib/listen/event/queue.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/event/queue.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/event/queue.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/event/queue.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/listen-3.0.3/lib/listen/event/queue.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/listen-3.0.3/lib/listen/event/queue.rb
geminfo-0.1.0 path/gems/listen-3.0.3/lib/listen/event/queue.rb
listen-3.0.3 lib/listen/event/queue.rb