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 "      Please fix the configuration\n\n      config/app.rb\n\n         config.cloud.\#{name} = '...'\n\n    EOL\n    exit 1\n  end\nend\n"