Class: Listen::Event::Queue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/listen/event/queue.rb

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Queue

Returns a new instance of Queue.



22
23
24
25
# File 'lib/listen/event/queue.rb', line 22

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

Instance Method Details

#<<(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/listen/event/queue.rb', line 27

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 = if @config.relative?
    _safe_relative_from_cwd(dir)
  else
    dir
  end
  @event_queue << [type, change, dir, path, options]
end

#_safe_relative_from_cwd(dir) ⇒ Object (private)



47
48
49
50
51
# File 'lib/listen/event/queue.rb', line 47

def _safe_relative_from_cwd(dir)
  dir.relative_path_from(Pathname.pwd)
rescue ArgumentError
  dir
end