Sha256: 59cb8f9d7a38bba5a6a91b5c5848608177c60a1a54625f557a962c2bb00decab

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

module Berkshelf
  module Vagrant
    # A module of common helper functions that can be mixed into Berkshelf::Vagrant actions
    module EnvHelpers
      # A file to persist vagrant-berkshelf specific information in between
      # Vagrant runs.
      #
      # @return [String]
      def cache_file(env)
        File.expand_path(File.join('.vagrant', 'machines', env[:machine].name.to_s, 'berkshelf'), env[:root_path].to_s)
      end

      # Filter all of the provisioners of the given vagrant environment with the given name
      #
      # @param [Symbol] name
      #   name of provisioner to filter
      # @param [Vagrant::Environment, Hash] env
      #   environment to inspect
      #
      # @return [Array]
      def provisioners(name, env)
        env[:machine].config.vm.provisioners.select { |prov| prov.name == name }
      end

      # Determine if the given vagrant environment contains a chef_solo provisioner
      #
      # @param [Vagrant::Environment] env
      #
      # @return [Boolean]
      def chef_solo?(env)
        provisioners(:chef_solo, env).any?
      end

      # Determine if the given vagrant environment contains a chef_client provisioner
      #
      # @param [Vagrant::Environment] env
      #
      # @return [Boolean]
      def chef_client?(env)
        provisioners(:chef_client, env).any?
      end

      # Determine if the Berkshelf plugin should be run for the given environment
      #
      # @param [Vagrant::Environment] env
      #
      # @return [Boolean]
      def berkshelf_enabled?(env)
        env[:machine].config.berkshelf.enabled
      end

      # Determine if --no-provision was specified
      #
      # @param [Vagrant::Environment] env
      #
      # @return [Boolean]
      def provision_disabled?(env)
        env.has_key?(:provision_enabled) && !env[:provision_enabled]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-berkshelf-2.0.1 lib/berkshelf/vagrant/env_helpers.rb
vagrant-berkshelf-2.0.0.rc4 lib/berkshelf/vagrant/env_helpers.rb
vagrant-berkshelf-2.0.0.rc3 lib/berkshelf/vagrant/env_helpers.rb