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.



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/autorake/compile.rb', line 119

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.



117
118
119
# File 'lib/autorake/compile.rb', line 117

def src
  @src
end

Class Method Details

.open(source) ⇒ Object



108
109
110
111
112
113
# File 'lib/autorake/compile.rb', line 108

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

Instance Method Details

#binObject



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

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

#cleanupObject



136
137
138
139
140
141
# File 'lib/autorake/compile.rb', line 136

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



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

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

#objObject



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

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