Module: Terraspace::Cloud::Api::Validate

Included in:
Concern, Context
Defined in:
lib/terraspace/cloud/api/validate.rb

Instance Method Summary collapse

Instance Method Details

#validate(name, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/terraspace/cloud/api/validate.rb', line 3

def validate(name, value)
  unless value =~ /^[\w-]*$/
    message = "ERROR: #{name}: only allows letters, numbers, dashes, and underscores"
  end
  if value =~ /^[-_]/ || value =~ /[-_]$/
    message = "ERROR: #{name}: no leading or trailing underscore or dash allowed"
  end
  if message
    puts message.color(:red)
    puts <<~EOL
      Please fix the configuration

      config/app.rb

         config.cloud.#{name} = '...'

    EOL
    exit 1
  end
end