Module: Rake::Tilde
- Defined in:
- lib/rake/tilde.rb,
lib/rake/tilde/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .listen(**args, &blk) ⇒ Object
- .listeners ⇒ Object
- .listening? ⇒ Boolean
- .paths ⇒ Object
- .run(task_name, *task_args) ⇒ Object
- .sleep_forever ⇒ Object
Class Method Details
.listen(**args, &blk) ⇒ Object
14 15 16 17 18 |
# File 'lib/rake/tilde.rb', line 14 def listen(**args, &blk) name = args.delete(:to) args[:blk] = blk paths[name] = args end |
.listeners ⇒ Object
24 25 26 |
# File 'lib/rake/tilde.rb', line 24 def listeners @listeners ||= [] end |
.listening? ⇒ Boolean
20 21 22 |
# File 'lib/rake/tilde.rb', line 20 def listening? !listeners.empty? end |
.paths ⇒ Object
10 11 12 |
# File 'lib/rake/tilde.rb', line 10 def paths @paths ||= {} end |
.run(task_name, *task_args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rake/tilde.rb', line 28 def run(task_name, *task_args) task = Rake.application[task_name] listen_path = paths.fetch(task_name.intern) {{}} paths = listen_path.fetch(:paths, listen_path.fetch(:path) { Dir.pwd }) opts = listen_path.fetch(:opts) {{}} blk = listen_path[:blk] begin task.invoke(*task_args) rescue StandardError => exception $stderr.puts "** Task failed to run successfully with tilde" Rake.application.(exception) Rake.application.exit_because_of_exception(exception) end listener = Listen.to(paths, opts) do |modified, added, removed| $stdout.puts "** File system changed" begin pid = spawn("rake #{task.name}") Process.wait pid blk.call(modified, added, removed) if blk rescue StandardError => exception $stderr.puts "** Task failed to run successfully with tilde" Rake.application.(exception) end end listeners.push listener listener.start end |
.sleep_forever ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/rake/tilde.rb', line 59 def sleep_forever begin sleep rescue Interrupt puts end end |