Class: VagrantPlugins::Berkshelf::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::Berkshelf::Config
- Defined in:
- lib/vagrant-berkshelf/config.rb
Constant Summary collapse
- MAYBE =
Object.new.freeze
Instance Attribute Summary collapse
-
#args ⇒ Array<String>
An array of additional arguments to pass to the Berkshelf command.
-
#berksfile_path ⇒ String
The path to the Berksfile to use.
-
#enabled ⇒ Boolean
Disable the use of Berkshelf in Vagrant.
-
#except ⇒ Array<Symbol>
The array of cookbook groups to exclude during provisioning.
-
#only ⇒ Array<Symbol>
The array of cookbook groups to exclusively install during provisioning.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #missing?(obj) ⇒ Boolean
- #to_hash ⇒ Object
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vagrant-berkshelf/config.rb', line 29 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
#args ⇒ Array<String>
An array of additional arguments to pass to the Berkshelf command.
27 28 29 |
# File 'lib/vagrant-berkshelf/config.rb', line 27 def args @args end |
#berksfile_path ⇒ String
The path to the Berksfile to use.
11 12 13 |
# File 'lib/vagrant-berkshelf/config.rb', line 11 def berksfile_path @berksfile_path end |
#enabled ⇒ Boolean
Disable the use of Berkshelf in Vagrant.
15 16 17 |
# File 'lib/vagrant-berkshelf/config.rb', line 15 def enabled @enabled end |
#except ⇒ Array<Symbol>
The array of cookbook groups to exclude during provisioning.
23 24 25 |
# File 'lib/vagrant-berkshelf/config.rb', line 23 def except @except end |
#only ⇒ Array<Symbol>
The array of cookbook groups to exclusively install during provisioning.
19 20 21 |
# File 'lib/vagrant-berkshelf/config.rb', line 19 def only @only end |
Instance Method Details
#finalize! ⇒ Object
41 42 43 44 45 46 |
# File 'lib/vagrant-berkshelf/config.rb', line 41 def finalize! @berksfile_path = nil if @berksfile_path == UNSET_VALUE @enabled = MAYBE if @enabled == UNSET_VALUE @__finalized = true end |
#missing?(obj) ⇒ Boolean
102 103 104 |
# File 'lib/vagrant-berkshelf/config.rb', line 102 def missing?(obj) obj.to_s.strip.empty? end |
#to_hash ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vagrant-berkshelf/config.rb', line 90 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vagrant-berkshelf/config.rb', line 48 def validate(machine) errors = _detected_errors if @enabled || @enabled == MAYBE # If no Berksfile path was given, check if one is in the working # directory if !@berksfile_path path = File.("Berksfile", machine.env.root_path) if File.exist?(path) @enabled = true @berksfile_path = path else # Disable the plugin unless it was specifically set to "true". If # the user set the value, we want to return an error, but if the # user did not explicitly enable the plugin, we should just # disable it automatically. @enabled = false unless @enabled == true end end if @enabled # Berksfile_path validations if missing?(@berksfile_path) errors << "berksfile_path must be set" else # Expand the path unless it is absolute if !Pathname.new(@berksfile_path).absolute? @berksfile_path = File.(@berksfile_path, machine.env.root_path) end # Ensure the path exists if !File.exist?(@berksfile_path) errors << "Berksfile at '#{@berksfile_path}' does not exist" end end end end { "Berkshelf" => errors } end |