Sha256: 27284bed9cc28c732fcf9a0d4a76d2c4b884565ed10db88ba7988854155fbad1

Contents?: true

Size: 2 KB

Versions: 17

Compression:

Stored size: 2 KB

Contents

module VagrantPlugins
  module LocalExecPush
    class Config < Vagrant.plugin("2", :config)
      # The path (relative to the machine root) to a local script that will be
      # executed.
      # @return [String]
      attr_accessor :script

      # The command (as a string) to execute.
      # @return [String]
      attr_accessor :inline

      # The arguments to provide when executing the script.
      # @return [Array<String>]
      attr_accessor :args

      def initialize
        @script = UNSET_VALUE
        @inline = UNSET_VALUE
        @args   = UNSET_VALUE
      end

      def finalize!
        @script = nil if @script == UNSET_VALUE
        @inline = nil if @inline == UNSET_VALUE
        @args   = nil if @args == UNSET_VALUE

        if @args && args_valid?
          @args = @args.is_a?(Array) ? @args.map { |a| a.to_s } : @args.to_s
        end
      end

      def validate(machine)
        errors = _detected_errors

        if missing?(@script) && missing?(@inline)
          errors << I18n.t("local_exec_push.errors.missing_attribute",
            attribute: "script",
          )
        end

        if !missing?(@script) && !missing?(@inline)
          errors << I18n.t("local_exec_push.errors.cannot_specify_script_and_inline")
        end

        if !args_valid?
          errors << I18n.t("local_exec_push.errors.args_bad_type")
        end

        { "Local Exec push" => errors }
      end

      private

      # Determine if the given string is "missing" (blank)
      # @return [true, false]
      def missing?(obj)
        obj.to_s.strip.empty?
      end

      # Args are optional, but if they're provided we only support them as a
      # string or as an array.
      def args_valid?
        return true if !args
        return true if args.is_a?(String)
        return true if args.is_a?(Fixnum)
        if args.is_a?(Array)
          args.each do |a|
            return false if !a.kind_of?(String) && !a.kind_of?(Fixnum)
          end

          return true
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/pushes/local-exec/config.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/pushes/local-exec/config.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/pushes/local-exec/config.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/pushes/local-exec/config.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/pushes/local-exec/config.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.9.1.1 plugins/pushes/local-exec/config.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/pushes/local-exec/config.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/pushes/local-exec/config.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/pushes/local-exec/config.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.5.2 plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.5.1 plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.4.2 plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.4.1 plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.1.2 plugins/pushes/local-exec/config.rb
vagrant-unbundled-1.8.1.1 plugins/pushes/local-exec/config.rb