Sha256: be64961e86bc633dd07b95722ef87aa8e374a9c9bef8fd3d1268be50eb7a799e

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

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)
        @event_queue = ::Queue.new
        @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])
      end

      delegate empty?: :event_queue
      delegate pop: :event_queue
      delegate close: :event_queue

      private

      attr_reader :event_queue
      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

15 entries across 15 versions & 2 rubygems

Version Path
qiita_org-0.1.35 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/listen-3.3.1/lib/listen/event/queue.rb
listen-3.3.1 lib/listen/event/queue.rb
listen-3.3.0 lib/listen/event/queue.rb
listen-3.3.0.pre.3 lib/listen/event/queue.rb
listen-3.3.0.pre.2 lib/listen/event/queue.rb