Class: OptsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/opts_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, logger = nil) ⇒ OptsValidator

Returns a new instance of OptsValidator.



3
4
5
6
# File 'lib/opts_validator.rb', line 3

def initialize(options, logger = nil)
    @options = options
    @logger  = logger
end

Instance Method Details

#validate_presence_of(symbol, description = nil, flag = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/opts_validator.rb', line 8

def validate_presence_of(symbol, description = nil, flag = nil)
    if @options[symbol].nil?
        if description.nil?
            message = "You must provide the #{symbol} parameter"
        else
            message = "You must provide the #{description} parameter"
            message += " (-#{flag} flag)" unless flag.nil?
        end
        unless @logger.nil?
            @logger.error(message)
        else
            puts message.red
        end
        exit
    end
end