lib/berkshelf/vagrant/config.rb in berkshelf-vagrant-1.0.6 vs lib/berkshelf/vagrant/config.rb in berkshelf-vagrant-1.1.0

- old
+ new

@@ -6,10 +6,14 @@ # @return [String] # path to the Berksfile to use with Vagrant attr_reader :berksfile_path + # @return [Boolean] + # disable of use Berks in Vagrant + attr_accessor :enabled + # @return [Array<Symbol>] # only cookbooks in these groups will be installed and copied to # Vagrant's shelf attr_accessor :only @@ -34,10 +38,11 @@ @berksfile_path = File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME) @except = Array.new @only = Array.new @node_name = Berkshelf::Config.instance.chef.node_name @client_key = Berkshelf::Config.instance.chef.client_key + @enabled = false end # @param [String] value def berksfile_path=(value) @berksfile_path = File.expand_path(value) @@ -51,28 +56,34 @@ alias_method :to_hash, :instance_variables_hash def validate(machine) errors = Array.new - if machine.config.berkshelf.berksfile_path.nil? - errors << "berkshelf.berksfile_path cannot be nil." + unless [TrueClass, FalseClass].include?(enabled.class) + errors << "A value for berkshelf.enabled can be true or false." end - unless File.exist?(machine.config.berkshelf.berksfile_path) - errors << "No Berskfile was found at #{machine.config.berkshelf.berksfile_path}." - end + if enabled + if machine.config.berkshelf.berksfile_path.nil? + errors << "berkshelf.berksfile_path cannot be nil." + end - if !except.empty? && !only.empty? - errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined." - end + unless File.exist?(machine.config.berkshelf.berksfile_path) + errors << "No Berskfile was found at #{machine.config.berkshelf.berksfile_path}." + end - if chef_client?(machine.env) - if machine.config.berkshelf.node_name.nil? - errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration." + if !except.empty? && !only.empty? + errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined." end - if machine.config.berkshelf.client_key.nil? - errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration." + if chef_client?(machine.env) + if machine.config.berkshelf.node_name.nil? + errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration." + end + + if machine.config.berkshelf.client_key.nil? + errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration." + end end end { "berkshelf configuration" => errors } end