Class: Rubysh::TripleLessThan

Inherits:
BaseDirective show all
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

Instance Method Summary collapse

Methods inherited from BaseDirective

#state

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

#fdObject (readonly)

Returns the value of attribute fd.



6
7
8
# File 'lib/rubysh/triple_less_than.rb', line 6

def fd
  @fd
end

#literalObject (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

#stringifyObject



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_sObject



56
57
58
# File 'lib/rubysh/triple_less_than.rb', line 56

def to_s
  "TripleLessThan: #{stringify}"
end