Class: Bookbinder::CommandValidator
- Inherits:
-
Object
- Object
- Bookbinder::CommandValidator
- Defined in:
- lib/bookbinder/command_validator.rb
Defined Under Namespace
Classes: Candidate
Instance Method Summary collapse
-
#initialize(commands, usage_text) ⇒ CommandValidator
constructor
A new instance of CommandValidator.
- #validate(command_name) ⇒ Object
Constructor Details
#initialize(commands, usage_text) ⇒ CommandValidator
Returns a new instance of CommandValidator.
8 9 10 11 |
# File 'lib/bookbinder/command_validator.rb', line 8 def initialize(commands, usage_text) @commands = commands @usage_text = usage_text end |
Instance Method Details
#validate(command_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bookbinder/command_validator.rb', line 13 def validate(command_name) candidate = Candidate.new(command_name, commands) if candidate.unrecognized? UserMessage.new( "Unrecognized #{candidate.command_type} '#{command_name}'\n#{usage_text}", EscalationType.error ) elsif candidate.deprecated_match UserMessage.new( "Use of #{command_name} is deprecated. " + "The preferred usage is below: \nbookbinder #{candidate.deprecated_match.usage[0]}", EscalationType.warn ) else UserMessage.new "Success", EscalationType.success end end |