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.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/daedalus.rb', line 295

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.



312
313
314
# File 'lib/daedalus.rb', line 312

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



312
313
314
# File 'lib/daedalus.rb', line 312

def path
  @path
end

Instance Method Details

#artifacts_pathObject



318
319
320
321
322
# File 'lib/daedalus.rb', line 318

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

#basenameObject



314
315
316
# File 'lib/daedalus.rb', line 314

def basename
  File.basename @path
end

#data_pathObject



324
325
326
# File 'lib/daedalus.rb', line 324

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

#save!Object



328
329
330
331
332
# File 'lib/daedalus.rb', line 328

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