Class: SubSpawn::Internal::FdSource::File

Inherits:
Open show all
Defined in:
lib/subspawn/fd_types.rb

Instance Attribute Summary

Attributes inherited from SubSpawn::Internal::FdSource

#all_dests, #dests

Instance Method Summary collapse

Methods inherited from SubSpawn::Internal::FdSource

#before?, #depends?, #destroys?, #heads, #max, #raw_apply, #tails

Constructor Details

#initialize(dests, file, mode = ::File::RDONLY, perm = 0o666) ⇒ File

Returns a new instance of File.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/subspawn/fd_types.rb', line 91

def initialize(dests, file, mode = ::File::RDONLY, perm = 0o666)
  super(dests)
  @value = file
  @mode = mode || ::File::RDONLY
  if @mode.respond_to? :to_str
    @mode = case @mode.to_str
    when "w" then IO::WRONLY | IO::CREAT | IO::TRUNC
    when "r" then IO::RDONLY
    when "rb" then IO::RDONLY | IO::BINARY
    when "wb" then IO::WRONLY | IO::BINARY | IO::CREAT | IO::TRUNC
    when "r+", "w+" then IO::RDWR | IO::CREAT 
      # TODO: all!
    else
      raise ArgumentError "Unknown File mode"
    end
  end
  @perm = perm || 0o666
end

Instance Method Details

#apply(base) ⇒ Object



112
113
114
115
116
117
# File 'lib/subspawn/fd_types.rb', line 112

def apply base
  first, *rest = @dests
  base.fd_open(first, @value, @mode, @perm)
  rest.each {|dest| base.fd(dest, first) }
  nil
end

#to_dbgObject



109
110
111
# File 'lib/subspawn/fd_types.rb', line 109

def to_dbg
  [@dests, :file, @value, @mode, @perm]
end