Class: Captain::Remote::Cache::Persistent

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

Constant Summary collapse

PATH =
Pathname.new(ENV['HOME']).join('.captain')

Instance Method Summary collapse

Instance Method Details

#open(uri) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/captain/remote.rb', line 134

def open(uri)
  # I didn't expect to have to use string concatenation here, but PATH
  # gets confused when uri.path starts with a /.
  path = PATH.join("#{uri.host}#{uri.path}")
  if path.exist?
    path.open('r+') { |cache| yield populatable(cache) }
  else
    path.dirname.mkpath
    path.open('w+') { |cache| yield populatable(cache) }
  end
end