Class: VagrantPlugins::Cachier::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-cachier/config.rb

Constant Summary collapse

ALLOWED_SCOPES =
%w( box machine )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



9
10
11
12
13
# File 'lib/vagrant-cachier/config.rb', line 9

def initialize
  @scope       = UNSET_VALUE
  @auto_detect = UNSET_VALUE
  @enable_nfs  = UNSET_VALUE
end

Instance Attribute Details

#auto_detectObject

Returns the value of attribute auto_detect.



4
5
6
# File 'lib/vagrant-cachier/config.rb', line 4

def auto_detect
  @auto_detect
end

#bucketsObject (readonly)

Returns the value of attribute buckets.



5
6
7
# File 'lib/vagrant-cachier/config.rb', line 5

def buckets
  @buckets
end

#enable_nfsObject

Returns the value of attribute enable_nfs.



4
5
6
# File 'lib/vagrant-cachier/config.rb', line 4

def enable_nfs
  @enable_nfs
end

#scopeObject

Returns the value of attribute scope.



4
5
6
# File 'lib/vagrant-cachier/config.rb', line 4

def scope
  @scope
end

Instance Method Details

#enable(bucket, opts = {}) ⇒ Object



15
16
17
# File 'lib/vagrant-cachier/config.rb', line 15

def enable(bucket, opts = {})
  (@buckets ||= {})[bucket] = opts
end

#enabled?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/vagrant-cachier/config.rb', line 40

def enabled?
  @enabled ||= @auto_detect != UNSET_VALUE ||
               @buckets != nil
end

#finalize!Object



31
32
33
34
35
36
37
38
# File 'lib/vagrant-cachier/config.rb', line 31

def finalize!
  return unless enabled?

  @scope       = :box  if @scope == UNSET_VALUE
  @auto_detect = false if @auto_detect == UNSET_VALUE
  @enable_nfs  = false if @enable_nfs == UNSET_VALUE
  @buckets     = @buckets ? @buckets.dup : {}
end

#validate(machine) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-cachier/config.rb', line 19

def validate(machine)
  errors = _detected_errors

  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