Module: Rails::Sh::Forkable
Instance Method Summary collapse
- #_invoke ⇒ Object
- #after_fork(&block) ⇒ Object
- #before_fork(&block) ⇒ Object
- #invoke(line, options = {}) ⇒ Object
- #run_after_fork(&block) ⇒ Object
- #run_before_fork(&block) ⇒ Object
Methods included from Helpers
Instance Method Details
#_invoke ⇒ Object
30 31 32 |
# File 'lib/rails/sh/forkable.rb', line 30 def _invoke raise NotImplementedError end |
#after_fork(&block) ⇒ Object
38 39 40 |
# File 'lib/rails/sh/forkable.rb', line 38 def after_fork(&block) @after_fork = block end |
#before_fork(&block) ⇒ Object
34 35 36 |
# File 'lib/rails/sh/forkable.rb', line 34 def before_fork(&block) @before_fork = block end |
#invoke(line, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails/sh/forkable.rb', line 8 def invoke(line, = {}) run_before_fork pid = fork do run_after_fork if [:pager] begin $stdout = StringIO.new _invoke(line) ensure output = $stdout.string lesspipe output $stdout = STDOUT end else _invoke(line) end end Process.waitpid(pid) end |
#run_after_fork(&block) ⇒ Object
46 47 48 |
# File 'lib/rails/sh/forkable.rb', line 46 def run_after_fork(&block) @after_fork.call if @after_fork end |
#run_before_fork(&block) ⇒ Object
42 43 44 |
# File 'lib/rails/sh/forkable.rb', line 42 def run_before_fork(&block) @before_fork.call if @before_fork end |