Class: Pantograph::Actions::EnsureEnvVarsAction

Inherits:
Pantograph::Action show all
Defined in:
pantograph/lib/pantograph/actions/ensure_env_vars.rb

Constant Summary

Constants inherited from Pantograph::Action

Pantograph::Action::AVAILABLE_CATEGORIES, Pantograph::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Pantograph::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



36
37
38
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 36

def self.authors
  ['johnknapprs']
end

.available_optionsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 23

def self.available_options
  [
    PantographCore::ConfigItem.new(
      key: :vars,
      description: 'The ENV variables keys to verify',
      type: Array,
      verify_block: proc do |value|
        UI.user_error!('Specify at least one environment variable key') if value.empty?
      end
    )
  ]
end

.categoryObject



48
49
50
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 48

def self.category
  :misc
end

.descriptionObject



16
17
18
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 16

def self.description
  'Raises an exception if the specified env vars are not set'
end

.detailsObject



20
21
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 20

def self.details
end

.example_codeObject



40
41
42
43
44
45
46
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 40

def self.example_code
  [
    'ensure_env_vars(
      vars: [\'GITHUB_USER_NAME\', \'GITHUB_API_TOKEN\']
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



52
53
54
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 52

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'pantograph/lib/pantograph/actions/ensure_env_vars.rb', line 4

def self.run(params)
  null_keys = params[:vars].reject do |var|
    ENV.key?(var)
  end

  if null_keys.any?
    UI.user_error!("Unable to find ENV Variable(s):\n#{null_keys.join("\n")}")
  end

  UI.success("ENV variable(s) '#{params[:vars].join('\', \'')}' set!")
end