Class: Daedalus::Path
- Inherits:
-
Object
- Object
- Daedalus::Path
- Defined in:
- lib/daedalus.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #artifacts_path ⇒ Object
- #basename ⇒ Object
- #data_path ⇒ Object
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
- #save! ⇒ Object
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
312 313 314 |
# File 'lib/daedalus.rb', line 312 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
312 313 314 |
# File 'lib/daedalus.rb', line 312 def path @path end |
Instance Method Details
#artifacts_path ⇒ Object
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 |
#basename ⇒ Object
314 315 316 |
# File 'lib/daedalus.rb', line 314 def basename File.basename @path end |
#data_path ⇒ Object
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 |