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.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
291 292 293 |
# File 'lib/daedalus.rb', line 291 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
291 292 293 |
# File 'lib/daedalus.rb', line 291 def path @path end |
Instance Method Details
#artifacts_path ⇒ Object
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 |
#basename ⇒ Object
293 294 295 |
# File 'lib/daedalus.rb', line 293 def basename File.basename @path end |
#data_path ⇒ Object
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 |