Class: Rubysh::TripleLessThan
- Inherits:
-
BaseDirective
- Object
- BaseDirective
- Rubysh::TripleLessThan
- Defined in:
- lib/rubysh/triple_less_than.rb
Overview
Looks like bash always buffers <<< to disk
Defined Under Namespace
Classes: Shell
Instance Attribute Summary collapse
-
#fd ⇒ Object
readonly
Returns the value of attribute fd.
-
#literal ⇒ Object
readonly
Returns the value of attribute literal.
Instance Method Summary collapse
- #apply!(runner) ⇒ Object
- #apply_parent!(runner) ⇒ Object
-
#initialize(fd, literal) ⇒ TripleLessThan
constructor
TODO: support in-place strings.
- #prepare!(runner) ⇒ Object
- #stringify ⇒ Object
- #to_s ⇒ Object
Methods inherited from BaseDirective
Constructor Details
#initialize(fd, literal) ⇒ TripleLessThan
TODO: support in-place strings
28 29 30 31 |
# File 'lib/rubysh/triple_less_than.rb', line 28 def initialize(fd, literal) @fd = fd @literal = literal end |
Instance Attribute Details
#fd ⇒ Object (readonly)
Returns the value of attribute fd.
6 7 8 |
# File 'lib/rubysh/triple_less_than.rb', line 6 def fd @fd end |
#literal ⇒ Object (readonly)
Returns the value of attribute literal.
6 7 8 |
# File 'lib/rubysh/triple_less_than.rb', line 6 def literal @literal end |
Instance Method Details
#apply!(runner) ⇒ Object
66 67 68 69 |
# File 'lib/rubysh/triple_less_than.rb', line 66 def apply!(runner) state = state(runner) state[:redirect].apply!(runner) end |
#apply_parent!(runner) ⇒ Object
60 61 62 63 64 |
# File 'lib/rubysh/triple_less_than.rb', line 60 def apply_parent!(runner) state = state(runner) state[:tempfile].close state[:redirect].apply_parent!(runner) end |
#prepare!(runner) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubysh/triple_less_than.rb', line 33 def prepare!(runner) tempfile = Tempfile.new('buffer') tempfile_read_only = File.open(tempfile.path, 'r') tempfile.delete tempfile.write(@literal) tempfile.flush tempfile.rewind tempfile.close Util.set_cloexec(tempfile_read_only) state = state(runner) state[:tempfile] = tempfile_read_only state[:redirect] = Redirect.new(@fd, '<', tempfile_read_only) end |
#stringify ⇒ Object
50 51 52 53 54 |
# File 'lib/rubysh/triple_less_than.rb', line 50 def stringify fd = Util.to_fileno(@fd) beginning = fd == 0 ? '' : fd.to_s "#{beginning}<<< (#{@literal.bytesize} bytes)" end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/rubysh/triple_less_than.rb', line 56 def to_s "TripleLessThan: #{stringify}" end |