Sha256: dcc40bf4ac82fb8c5a1f874a86d65ad30499d52fe0b425a60d0c2afaac0b3547

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

module Pantograph
  module Actions
    class EnsureEnvVarsAction < Action
      def self.run(params)
        variables = params[:env_vars]

        variables.each do |variable|
          next unless ENV[variable].to_s.strip.empty?

          UI.user_error!("Missing environment variable '#{variable}'")
        end

        is_one = variables.length == 1

        UI.success("Environment variable#{is_one ? '' : 's'} '#{variables.join('\', \'')}' #{is_one ? 'is' : 'are'} set!")
      end

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

      def self.details
        'This action will check if some environment variables are set.'
      end

      def self.available_options
        [
          PantographCore::ConfigItem.new(key: :env_vars,
                                       description: 'The environment variables names that should be checked',
                                       type: Array,
                                       verify_block: proc do |value|
                                         UI.user_error!('Specify at least one environment variable name') if value.empty?
                                       end)
        ]
      end

      def self.authors
        ['revolter']
      end

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

      def self.category
        :misc
      end

      def self.is_supported?(platform)
        true
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pantograph-0.1.14 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.13 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.12 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.10 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.8 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.7 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.6 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.4 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.3 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.1 pantograph/lib/pantograph/actions/ensure_env_vars.rb
pantograph-0.1.0 pantograph/lib/pantograph/actions/ensure_env_vars.rb