Class: Coque::Rb
Constant Summary collapse
- NOOP =
Proc.new { }
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#post_block ⇒ Object
readonly
Returns the value of attribute post_block.
-
#pre_block ⇒ Object
readonly
Returns the value of attribute pre_block.
Attributes inherited from Cmd
Attributes included from Redirectable
Instance Method Summary collapse
- #clone ⇒ Object
- #get_result ⇒ Object
-
#initialize(context = Context.new, &block) ⇒ Rb
constructor
A new instance of Rb.
- #post(&block) ⇒ Object
- #pre(&block) ⇒ Object
Methods inherited from Cmd
Methods included from Runnable
#log_start, #run, #run!, #success?, #to_a, #to_a!
Methods included from Redirectable
#<, #>, #>=, #err, #getio, #in, #out
Constructor Details
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/coque/rb.rb', line 4 def block @block end |
#post_block ⇒ Object (readonly)
Returns the value of attribute post_block.
4 5 6 |
# File 'lib/coque/rb.rb', line 4 def post_block @post_block end |
#pre_block ⇒ Object (readonly)
Returns the value of attribute pre_block.
4 5 6 |
# File 'lib/coque/rb.rb', line 4 def pre_block @pre_block end |
Instance Method Details
#clone ⇒ Object
16 17 18 |
# File 'lib/coque/rb.rb', line 16 def clone self.class.new(context, &block).pre(&pre_block).post(&post_block) end |
#get_result ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/coque/rb.rb', line 34 def get_result stdin, stdoutr, stdoutw = get_default_fds pid = fork do STDOUT.reopen(stdoutw) Dir.chdir(context.dir) if context.disinherits_env? ENV.clear end context.env.each do |k,v| ENV[k] = v end @pre_block.call if @pre_block stdin.each_line(&@block) @post_block.call if @post_block end stdoutw.close Result.new(pid, stdoutr) end |
#post(&block) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/coque/rb.rb', line 27 def post(&block) if block_given? @post_block = block end self end |
#pre(&block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/coque/rb.rb', line 20 def pre(&block) if block_given? @pre_block = block end self end |