Class: CLIArgValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-globs/cli_arg_validator.rb

Constant Summary collapse

CONSTANT_TOKENS =
('A'..'Z').to_a << '_'
ERROR_MESSAGES =
{
  'invalid_options'           => 'Only one option is supported: \'-e (explanation)\'.',
  'invalid_identifier_count'  => "Globs accepts only one argument: e.g. '$!'.",
  'invalid_identifier_token'  =>
    'Invalid Ruby identifier. It has to be valid global variable ("$0") or a valid constant token. ("RUBY_VERSION")',
  'invalid_argument_presence' => 'You have to pass at least one argument and it has to be an identifier.'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_args) ⇒ CLIArgValidator

Returns a new instance of CLIArgValidator.



13
14
15
# File 'lib/pry-globs/cli_arg_validator.rb', line 13

def initialize(cli_args)
  @cli_args = cli_args
end

Instance Attribute Details

#cli_argsObject (readonly)

Returns the value of attribute cli_args.



11
12
13
# File 'lib/pry-globs/cli_arg_validator.rb', line 11

def cli_args
  @cli_args
end

Instance Method Details

#args_invalid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pry-globs/cli_arg_validator.rb', line 17

def args_invalid?
  invalid_argument_presence? || invalid_options? || identifiers_invalid?
end

#args_invalid_msgObject



21
22
23
24
25
26
27
# File 'lib/pry-globs/cli_arg_validator.rb', line 21

def args_invalid_msg
  method_names = %w(options identifier_count identifier_token argument_presence)
  method_names.each_with_object([]) do |method, memo|
    method = "invalid_#{method}"
    memo << ERROR_MESSAGES[method] if send("#{method}?")
  end.join("\n\n")
end