Class: Daedalus::Path

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

Direct Known Subclasses

Program, SourceFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Path

Returns a new instance of Path.



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/daedalus.rb', line 274

def initialize(path)
  @path = path

  if File.exist?(data_path)
    begin
      File.open data_path, "rb" do |f|
        @data = Marshal.load(f.read)
      end
    rescue
      STDERR.puts "WARNING: Path#initialize: load '#{data_path}' failed"
      @data = {}
    end
  else
    @data = {}
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



291
292
293
# File 'lib/daedalus.rb', line 291

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



291
292
293
# File 'lib/daedalus.rb', line 291

def path
  @path
end

Instance Method Details

#artifacts_pathObject



297
298
299
300
301
# File 'lib/daedalus.rb', line 297

def artifacts_path
  dir = File.join File.dirname(@path), "artifacts"
  Dir.mkdir dir unless File.directory?(dir)
  return dir
end

#basenameObject



293
294
295
# File 'lib/daedalus.rb', line 293

def basename
  File.basename @path
end

#data_pathObject



303
304
305
# File 'lib/daedalus.rb', line 303

def data_path
  File.join artifacts_path, "#{basename}.data"
end

#save!Object



307
308
309
310
311
# File 'lib/daedalus.rb', line 307

def save!
  File.open(data_path, "wb") do |f|
    f << Marshal.dump(data)
  end
end