class VagrantPlugins::Cachier::Config

Constants

ALLOWED_SCOPES

Attributes

auto_detect[RW]
buckets[R]
scope[RW]
synced_folder_opts[RW]

Public Class Methods

new() click to toggle source
# File lib/vagrant-cachier/config.rb, line 9
def initialize
  @scope = UNSET_VALUE
  @auto_detect = UNSET_VALUE
  @synced_folder_opts = UNSET_VALUE
  @ui = Vagrant::UI::Colored.new
end

Public Instance Methods

disable!() click to toggle source
# File lib/vagrant-cachier/config.rb, line 44
def disable!
  @enabled = false
end
enable(bucket, opts = {}) click to toggle source
# File lib/vagrant-cachier/config.rb, line 16
def enable(bucket, opts = {})
  (@buckets ||= {})[bucket] = opts
end
enabled?() click to toggle source
# File lib/vagrant-cachier/config.rb, line 38
def enabled?
  return @enabled unless @enabled.nil?

  @enabled = @scope != UNSET_VALUE
end
finalize!() click to toggle source
# File lib/vagrant-cachier/config.rb, line 48
def finalize!
  return unless enabled?

  @auto_detect = true if @auto_detect == UNSET_VALUE
  @synced_folder_opts = nil if @synced_folder_opts == UNSET_VALUE
  @buckets = @buckets ? @buckets.dup : {}
end
validate(machine) click to toggle source
# File lib/vagrant-cachier/config.rb, line 20
def validate(machine)
  errors = _detected_errors

  if enabled? && backed_by_cloud_provider?(machine)
    machine.ui.warn(I18n.t('vagrant_cachier.backed_by_cloud_provider',
                           provider: machine.provider_name))
    disable!
  end

  if enabled? && ! ALLOWED_SCOPES.include?(@scope.to_s)
    errors << I18n.t('vagrant_cachier.unknown_cache_scope',
                      allowed:     ALLOWED_SCOPES.inspect,
                      cache_scope: @scope)
  end

  { "vagrant cachier" => errors }
end

Private Instance Methods

backed_by_cloud_provider?(machine) click to toggle source
# File lib/vagrant-cachier/config.rb, line 58
def backed_by_cloud_provider?(machine)
  CLOUD_PROVIDERS.include?(machine.provider_name.to_s)
end