Class: Vagrant::Cachier::Action::Install
- Inherits:
-
Object
- Object
- Vagrant::Cachier::Action::Install
- Defined in:
- lib/vagrant-cachier/action.rb
Instance Method Summary collapse
- #cache_root ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Install
constructor
A new instance of Install.
Constructor Details
#initialize(app, env) ⇒ Install
Returns a new instance of Install.
7 8 9 10 |
# File 'lib/vagrant-cachier/action.rb', line 7 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::cachier::action::install") end |
Instance Method Details
#cache_root ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant-cachier/action.rb', line 42 def cache_root @cache_root ||= case @env[:machine].config.cache.scope when :box @env[:home_path].join('cache', @env[:machine].box.name) when :machine @env[:machine].data_dir.join('cache') else raise "Unknown cache scope: '#{@env[:machine].config.cache.scope}'" end end |
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vagrant-cachier/action.rb', line 12 def call(env) return @app.call(env) unless env[:machine].config.cache.enabled? @env = env FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', id: "vagrant-cache" @app.call env env[:cache_dirs] = [] if env[:machine].config.cache.auto_detect Bucket.auto_detect(env) end if env[:machine].config.cache.buckets.any? env[:ui].info 'Configuring cache buckets...' cache_config = env[:machine].config.cache cache_config.buckets.each do |bucket_name, configs| @logger.debug "Installing #{bucket_name} with configs #{configs.inspect}" Bucket.install(bucket_name, env, configs) end data_file = env[:machine].data_dir.join('cache_dirs') data_file.open('w') { |f| f.print env[:cache_dirs].join("\n") } end end |