Class: Optopus::CheckerContext

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

Overview

DefinerContext

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, &block) ⇒ CheckerContext

Returns a new instance of CheckerContext.



65
66
67
68
# File 'lib/optopus.rb', line 65

def initialize(value, &block)
  @args = value ? [value] : []
  (class<<self; self; end).send(:define_method, :evaluate, &block)
end

Class Method Details

.evaluate(args, pass, &block) ⇒ Object



61
62
63
# File 'lib/optopus.rb', line 61

def self.evaluate(args, pass, &block)
  self.new(args, &block).evaluate(pass)
end

Instance Method Details

#ambiguous_argument(*args) ⇒ Object

Raises:

  • (OptionParser::AmbiguousArgument)


102
103
104
105
# File 'lib/optopus.rb', line 102

def ambiguous_argument(*args)
  args = @args if args.empty?
  raise OptionParser::AmbiguousArgument.new(*args)
end

#ambiguous_option(*args) ⇒ Object

Raises:

  • (OptionParser::AmbiguousOption)


77
78
79
80
# File 'lib/optopus.rb', line 77

def ambiguous_option(*args)
  args = @args if args.empty?
  raise OptionParser::AmbiguousOption.new(*args)
end

#invalid_argument(*args) ⇒ Object

Raises:

  • (OptionParser::InvalidArgument)


97
98
99
100
# File 'lib/optopus.rb', line 97

def invalid_argument(*args)
  args = @args if args.empty?
  raise OptionParser::InvalidArgument.new(*args)
end

#invalid_option(*args) ⇒ Object

Raises:

  • (OptionParser::InvalidOption)


92
93
94
95
# File 'lib/optopus.rb', line 92

def invalid_option(*args)
  args = @args if args.empty?
  raise OptionParser::InvalidOption.new(*args)
end

#missing_argument(*args) ⇒ Object

Raises:

  • (OptionParser::MissingArgument)


87
88
89
90
# File 'lib/optopus.rb', line 87

def missing_argument(*args)
  args = @args if args.empty?
  raise OptionParser::MissingArgument.new(*args)
end

#needless_argument(*args) ⇒ Object

Raises:

  • (OptionParser::NeedlessArgument)


82
83
84
85
# File 'lib/optopus.rb', line 82

def needless_argument(*args)
  args = @args if args.empty?
  raise OptionParser::NeedlessArgument.new(*args)
end

#not_given(*args) ⇒ Object



107
108
109
110
# File 'lib/optopus.rb', line 107

def not_given(*args)
  args = @args if args.empty?
  raise OptionParser::NotGiven.new(*args)
end

#parse_error(reason, *args) ⇒ Object



70
71
72
73
74
75
# File 'lib/optopus.rb', line 70

def parse_error(reason, *args)
  args = @args if args.empty?
  e = OptionParser::ParseError.new(*args)
  e.reason = reason
  raise e
end