Sha256: 1d7ebf8ce4546b56146f4ee7c5acc8bae6bb273dd2f75f946ef1379f082f2f4a

Contents?: true

Size: 1.2 KB

Versions: 54

Compression:

Stored size: 1.2 KB

Contents

require 'thread'

require 'forwardable'

module Listen
  module Event
    class Queue
      extend Forwardable

      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

      delegate empty?: :event_queue
      delegate pop: :event_queue

      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

54 entries across 47 versions & 9 rubygems

Version Path
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/listen-3.2.1/lib/listen/event/queue.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/listen-3.1.5/lib/listen/event/queue.rb
listen-3.2.1 lib/listen/event/queue.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/event/queue.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
listen-3.2.0 lib/listen/event/queue.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/listen-3.1.5/lib/listen/event/queue.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/queue.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/listen-3.1.5/lib/listen/event/queue.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/listen-3.1.5/lib/listen/event/queue.rb