Sha256: 26020d5a5796cc4c022aea14c51b94dcc7dae06c891cfb7c2438d83ffe407794

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module VagrantPlugins
  module Exec
    class Config < Vagrant.plugin(2, :config)

      attr_reader :env
      attr_accessor :root

      def initialize
        @env          = {}
        @prepend_with = UNSET_VALUE
        @root         = UNSET_VALUE
      end

      def prepend_with(command, opts = {})
        @prepend_with = [] if @prepend_with == UNSET_VALUE
        @prepend_with << { :command => command }.merge(opts)
      end

      def prepends
        @prepend_with
      end

      def validate(_)
        return { 'exec' => ['root should be a string'] } unless @root.is_a?(String)
        if @prepend_with.any?
          if !@prepend_with.all? { |p| p[:command].is_a?(String) }
            return { 'exec' => ['prepend_with command should be a string'] }
          end
          if !@prepend_with.all? { |p| !p[:only] || p[:only].is_a?(Array) }
            return { 'exec' => ['prepend_with :only should be an array'] }
          end
        end

        {}
      end

      def finalize!
        @root = '/vagrant' if @root == UNSET_VALUE
        @prepend_with = [] if @prepend_with == UNSET_VALUE
      end

    end # Config
  end # Exec
end # VagrantPlugins

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-exec-0.3.1 lib/vagrant-exec/config.rb
vagrant-exec-0.3.0 lib/vagrant-exec/config.rb