Class: BundleDepot::Cache
- Inherits:
-
Object
- Object
- BundleDepot::Cache
- Defined in:
- lib/bundle_depot/cache.rb
Constant Summary collapse
- DEFAULT_BUNDLE_DEPOT_CURRENT =
File.join(".bundle", "depot", "current")
- DEFAULT_BUNDLE_DEPOT_CACHE =
File.join(".bundle", "depot", "cache")
Instance Attribute Summary collapse
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch_local ⇒ Object
- #fetch_remote ⇒ Object
-
#initialize(local = FileSystemStore.new(Cache.cache_path), remote = FileSystemStore.new(File.join(".bundle", "depot", "remote")).with_packing) ⇒ Cache
constructor
A new instance of Cache.
- #remote_configured? ⇒ Boolean
- #store ⇒ Object
- #store_remote ⇒ Object
Constructor Details
#initialize(local = FileSystemStore.new(Cache.cache_path), remote = FileSystemStore.new(File.join(".bundle", "depot", "remote")).with_packing) ⇒ Cache
Returns a new instance of Cache.
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bundle_depot/cache.rb', line 133 def initialize(local = FileSystemStore.new(Cache.cache_path), remote = FileSystemStore.new(File.join(".bundle", "depot", "remote")).with_packing) if remote_configured? && !ENV["TEST"] remote = SCPStore.new(ENV["BUNDLE_DEPOT_SCP_HOST"], ENV["BUNDLE_DEPOT_SCP_USER"], ENV["BUNDLE_DEPOT_SCP_PASS"], "cache").with_packing end @local = local @remote = remote end |
Instance Attribute Details
#local ⇒ Object (readonly)
Returns the value of attribute local.
131 132 133 |
# File 'lib/bundle_depot/cache.rb', line 131 def local @local end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
131 132 133 |
# File 'lib/bundle_depot/cache.rb', line 131 def remote @remote end |
Class Method Details
.cache_path ⇒ Object
188 189 190 |
# File 'lib/bundle_depot/cache.rb', line 188 def self.cache_path ENV["BUNDLE_DEPOT_CACHE"] || DEFAULT_BUNDLE_DEPOT_CACHE end |
.current_bundle_path ⇒ Object
192 193 194 |
# File 'lib/bundle_depot/cache.rb', line 192 def self.current_bundle_path ENV["DEFAULT_BUNDLE_DEPOT_CURRENT"] || DEFAULT_BUNDLE_DEPOT_CURRENT end |
Instance Method Details
#fetch ⇒ Object
151 152 153 154 155 |
# File 'lib/bundle_depot/cache.rb', line 151 def fetch setup fetch_remote unless fetch_local manage_symlink end |
#fetch_local ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/bundle_depot/cache.rb', line 157 def fetch_local if local.cached?(digest) puts "=> Bundle found in local cache" true else puts "=> Bundle is not in local cache" end end |
#fetch_remote ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/bundle_depot/cache.rb', line 166 def fetch_remote return unless remote_configured? if remote.cached?(digest) puts "=> Bundle found in remote cache. Downloading!" remote.fetch(digest, local.path) else puts "=> Bundle is not in remote cache" end end |
#remote_configured? ⇒ Boolean
196 197 198 |
# File 'lib/bundle_depot/cache.rb', line 196 def remote_configured? ENV["BUNDLE_DEPOT_SCP_HOST"] end |
#store ⇒ Object
146 147 148 149 |
# File 'lib/bundle_depot/cache.rb', line 146 def store setup store_remote end |
#store_remote ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/bundle_depot/cache.rb', line 177 def store_remote raise RemoteConfigurationMissing unless remote_configured? if remote.cached?(digest) puts "=> Bundle is already in remote cache. Skipping upload." else puts "=> Uploading bundle to remote cache" remote.store(File.join(local.path, digest)) end end |