Class: VagrantPlugins::Cachier::Action::ConfigureBucketRoot
- Inherits:
-
Object
- Object
- VagrantPlugins::Cachier::Action::ConfigureBucketRoot
- Defined in:
- lib/vagrant-cachier/action/configure_bucket_root.rb
Instance Method Summary collapse
- #box_name ⇒ Object
- #cache_root ⇒ Object
- #call(env) ⇒ Object
- #image_name ⇒ Object
-
#initialize(app, env) ⇒ ConfigureBucketRoot
constructor
A new instance of ConfigureBucketRoot.
- #setup_buckets_folder ⇒ Object
Constructor Details
#initialize(app, env) ⇒ ConfigureBucketRoot
Returns a new instance of ConfigureBucketRoot.
7 8 9 10 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 7 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::cachier::action::clean") end |
Instance Method Details
#box_name ⇒ Object
57 58 59 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 57 def box_name @env[:machine].config.vm.box end |
#cache_root ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 33 def cache_root @cache_root ||= case @env[:machine].config.cache.scope.to_sym when :box @box_name = box_name # Box is optional with docker provider if @box_name.nil? && @env[:machine].provider_name.to_sym == :docker @image_name = image_name # Use the image name if it's set if @image_name bucket_name = @image_name.gsub(':', '-') else raise "Cachier plugin only supported with docker provider when image is used" end else bucket_name = @box_name end @env[:home_path].join('cache', bucket_name) when :machine @env[:machine].data_dir.parent.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 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 12 def call(env) @env = env if !env[:cache_buckets_folder_configured] && env[:machine].config.cache.enabled? setup_buckets_folder env[:cache_buckets_folder_configured] = true end @app.call env end |
#image_name ⇒ Object
61 62 63 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 61 def image_name @env[:machine].provider_config.image end |
#setup_buckets_folder ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-cachier/action/configure_bucket_root.rb', line 23 def setup_buckets_folder FileUtils.mkdir_p(cache_root.to_s) unless cache_root.exist? synced_folder_opts = {id: "vagrant-cache"} synced_folder_opts.merge!(@env[:machine].config.cache.synced_folder_opts || {}) @env[:machine].config.vm.synced_folder cache_root, '/tmp/vagrant-cache', synced_folder_opts @env[:cache_dirs] = [] end |