Class: VagrantPlugins::Berkshelf::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vagrant-berkshelf/config.rb', line 27

def initialize
  super

  @berksfile_path = UNSET_VALUE
  @enabled        = UNSET_VALUE
  @except         = Array.new
  @only           = Array.new
  @args           = Array.new

  @__finalized = false
end

Instance Attribute Details

#argsArray<String>

An array of additional arguments to pass to the Berkshelf command.

Returns:

  • (Array<String>)


25
26
27
# File 'lib/vagrant-berkshelf/config.rb', line 25

def args
  @args
end

#berksfile_pathString

The path to the Berksfile to use.

Returns:

  • (String)


9
10
11
# File 'lib/vagrant-berkshelf/config.rb', line 9

def berksfile_path
  @berksfile_path
end

#enabledBoolean

Disable the use of Berkshelf in Vagrant.

Returns:

  • (Boolean)


13
14
15
# File 'lib/vagrant-berkshelf/config.rb', line 13

def enabled
  @enabled
end

#exceptArray<Symbol>

The array of cookbook groups to exclude during provisioning.

Returns:

  • (Array<Symbol>)


21
22
23
# File 'lib/vagrant-berkshelf/config.rb', line 21

def except
  @except
end

#onlyArray<Symbol>

The array of cookbook groups to exclusively install during provisioning.

Returns:

  • (Array<Symbol>)


17
18
19
# File 'lib/vagrant-berkshelf/config.rb', line 17

def only
  @only
end

Instance Method Details

#finalize!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-berkshelf/config.rb', line 39

def finalize!
  @berksfile_path = nil if @berksfile_path == UNSET_VALUE

  if @enabled == UNSET_VALUE
    if @berksfile_path
      # Automatically enable if a Berksfile path was given
      @enabled = true
    elsif File.exist?("Berksfile")
      # Automatically enable when a Berksfile is persent
      @berksfile_path = "Berksfile"
      @enabled = true
    end
  end

  @enabled = false if @enabled == UNSET_VALUE

  @__finalized = true
end

#to_hashObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vagrant-berkshelf/config.rb', line 74

def to_hash
  raise "Must finalize first." if !@__finalized

  {
    enabled:        @enabled,
    berksfile_path: @berksfile_path,
    except:         @except,
    only:           @only,
    args:           @args,
  }
end

#validate(machine) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vagrant-berkshelf/config.rb', line 58

def validate(machine)
  errors = _detected_errors

  if @enabled
    if @berksfile_path.to_s.strip.empty?
      errors << "berksfile_path must be set"
    else
      unless Pathname.new(@berksfile_path).absolute?
        @berksfile_path = File.expand_path(@berksfile_path, machine.env.root_path)
      end
    end
  end

  { "Berkshelf" => errors }
end