Class: Autorake::Builder::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.



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/autorake/compile.rb', line 73

def initialize source
  @plain = "autorake-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.



71
72
73
# File 'lib/autorake/compile.rb', line 71

def src
  @src
end

Class Method Details

.open(source, keep = nil) ⇒ Object



62
63
64
65
66
67
# File 'lib/autorake/compile.rb', line 62

def open source, keep = nil
  i = new source
  yield i
ensure
  i.cleanup unless keep
end

Instance Method Details

#binObject



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

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

#cleanupObject



90
91
92
93
94
95
# File 'lib/autorake/compile.rb', line 90

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



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

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

#objObject



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

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