Exception: Invokr::InputError

Inherits:
ArgumentError
  • Object
show all
Defined in:
lib/invokr/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(missing_args) ⇒ InputError

Returns a new instance of InputError.



5
6
7
8
# File 'lib/invokr/errors.rb', line 5

def initialize missing_args
  @missing_args = missing_args
  missing_args.map! do |arg| display arg end
end

Instance Attribute Details

#missing_argsObject (readonly)

Returns the value of attribute missing_args.



3
4
5
# File 'lib/invokr/errors.rb', line 3

def missing_args
  @missing_args
end

Instance Method Details

#build_messageObject



14
15
16
17
18
# File 'lib/invokr/errors.rb', line 14

def build_message
  prefix = "cannot invoke; missing required arguments: "
  prefix << concat_missing_args
  prefix
end

#concat_missing_argsObject



20
21
22
23
24
# File 'lib/invokr/errors.rb', line 20

def concat_missing_args
  return missing_args.first if missing_args.size == 1
  last_arg = missing_args.pop
  "#{missing_args.join ', '} and #{last_arg}"
end

#display(arg) ⇒ Object



26
27
28
29
30
31
# File 'lib/invokr/errors.rb', line 26

def display arg
  list = Array(arg).map do |arg| "`#{arg}'" end
  str = list * " or "
  str.insert 0, "either " if list.size > 1
  str
end

#messageObject



10
11
12
# File 'lib/invokr/errors.rb', line 10

def message
  @message ||= build_message
end