File: config.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (74 lines) | stat: -rw-r--r-- 2,001 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
module VagrantPlugins
  module HerokuPush
    class Config < Vagrant.plugin("2", :config)
      # The name of the Heroku application to push to.
      # @return [String]
      attr_accessor :app

      # The base directory with file contents to upload. By default this
      # is the same directory as the Vagrantfile, but you can specify this
      # if you have a `src` folder or `bin` folder or some other folder
      # you want to upload. This directory must be a git repository.
      # @return [String]
      attr_accessor :dir

      # The path to the git binary to shell out to. This usually is only set for
      # debugging/development. If not set, the git bin will be searched for
      # in the PATH.
      # @return [String]
      attr_accessor :git_bin

      # The Git remote to push to (default: "heroku").
      # @return [String]
      attr_accessor :remote

      def initialize
        @app = UNSET_VALUE
        @dir = UNSET_VALUE

        @git_bin = UNSET_VALUE
        @remote = UNSET_VALUE
      end

      def finalize!
        @app = nil if @app == UNSET_VALUE
        @dir = "." if @dir == UNSET_VALUE

        @git_bin = "git" if @git_bin == UNSET_VALUE
        @remote = "heroku" if @remote == UNSET_VALUE
      end

      def validate(machine)
        errors = _detected_errors

        if missing?(@dir)
          errors << I18n.t("heroku_push.errors.missing_attribute",
            attribute: "dir",
          )
        end

        if missing?(@git_bin)
          errors << I18n.t("heroku_push.errors.missing_attribute",
            attribute: "git_bin",
          )
        end

        if missing?(@remote)
          errors << I18n.t("heroku_push.errors.missing_attribute",
            attribute: "remote",
          )
        end

        { "Heroku push" => errors }
      end

      private

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