Class: MightyTest::Watcher::EventQueue
- Inherits:
-
Object
- Object
- MightyTest::Watcher::EventQueue
- Defined in:
- lib/mighty_test/watcher/event_queue.rb
Instance Method Summary collapse
-
#initialize(console: Console.new, file_system: FileSystem.new) ⇒ EventQueue
constructor
A new instance of EventQueue.
- #pop ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(console: Console.new, file_system: FileSystem.new) ⇒ EventQueue
Returns a new instance of EventQueue.
6 7 8 9 10 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 6 def initialize(console: Console.new, file_system: FileSystem.new) @console = console @file_system = file_system @file_system_queue = Thread::Queue.new end |
Instance Method Details
#pop ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 12 def pop console.with_raw_input do until stopped? if (key = console.read_keypress_nonblock) return [:keypress, key] end if (paths = pop_files_changed) return [:file_system_changed, paths] end end end end |
#restart ⇒ Object
35 36 37 38 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 35 def restart stop start end |
#start ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 25 def start raise "Already started" unless stopped? @file_system_listener = file_system.listen do |modified, added, _removed| paths = [*modified, *added].uniq file_system_queue.push(paths) unless paths.empty? end true end |
#stop ⇒ Object
40 41 42 43 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 40 def stop file_system_listener&.stop @file_system_listener = nil end |
#stopped? ⇒ Boolean
45 46 47 |
# File 'lib/mighty_test/watcher/event_queue.rb', line 45 def stopped? !file_system_listener end |