Class: Autorake::TmpFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/autorake/compile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ TmpFiles

Returns a new instance of TmpFiles.



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/autorake/compile.rb', line 107

def initialize source
  @plain = "tmp-0001"
  begin
    @src = "#@plain.c"
    File.open @src, File::WRONLY|File::CREAT|File::EXCL do |c|
      c.puts source
    end
  rescue Errno::EEXIST
    @plain.succ!
    retry
  end
end

Instance Attribute Details

#srcObject (readonly)

Returns the value of attribute src.



105
106
107
# File 'lib/autorake/compile.rb', line 105

def src
  @src
end

Class Method Details

.open(source) ⇒ Object



96
97
98
99
100
101
# File 'lib/autorake/compile.rb', line 96

def open source
  i = new source
  yield i
ensure
  i.cleanup
end

Instance Method Details

#binObject



122
# File 'lib/autorake/compile.rb', line 122

def bin ; @bin = "#@plain"     ; end

#cleanupObject



124
125
126
127
128
129
# File 'lib/autorake/compile.rb', line 124

def cleanup
  File.delete @bin if @bin and File.exists? @bin
  File.delete @obj if @obj and File.exists? @obj
  File.delete @cpp if @cpp and File.exists? @cpp
  File.delete @src
end

#cppObject



120
# File 'lib/autorake/compile.rb', line 120

def cpp ; @cpp = "#@plain.cpp" ; end

#objObject



121
# File 'lib/autorake/compile.rb', line 121

def obj ; @obj = "#@plain.o"   ; end