Class: OptParseValidator::OptCredentials

Inherits:
OptBase
  • Object
show all
Defined in:
lib/opt_parse_validator/opts/credentials.rb

Overview

Implementation of the Credentials Option

Instance Attribute Summary

Attributes inherited from OptBase

#attrs, #option, #required

Instance Method Summary collapse

Methods inherited from OptBase

#choices, #default, #initialize, #normalize, #required?, #required_unless, #to_long, #to_s, #to_sym, #value_if_empty

Constructor Details

This class inherits a constructor from OptParseValidator::OptBase

Instance Method Details

#validate(value) ⇒ Hash

Returns A hash containing the :username and :password.

Returns:

  • (Hash)

    A hash containing the :username and :password



5
6
7
8
9
10
11
12
# File 'lib/opt_parse_validator/opts/credentials.rb', line 5

def validate(value)
  unless value.index(':')
    fail 'Incorrect credentials format, username:password expected'
  end
  creds = value.split(':', 2)

  { username: creds[0], password: creds[1] }
end