-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to collapse parser various arguments into parameters list
- Loading branch information
1 parent
a078347
commit b239530
Showing
5 changed files
with
87 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require "set" | ||
|
||
module TTY | ||
module Option | ||
# A collection to hold all parameters | ||
class Parameters | ||
# A list of arguments | ||
attr_reader :arguments | ||
|
||
# A list of keywords | ||
attr_reader :keywords | ||
|
||
# A list of environments | ||
attr_reader :environments | ||
|
||
# A list of all parameters | ||
attr_reader :all | ||
|
||
# A parameters list | ||
# | ||
# @api private | ||
def initialize | ||
@arguments = [] | ||
@environments = [] | ||
@keywords = [] | ||
@all = [] | ||
|
||
@registered_names = Set.new | ||
end | ||
|
||
# Add parameter | ||
# | ||
# @api public | ||
def <<(parameter) | ||
if @registered_names.include?(parameter.name) | ||
raise ParameterConflict, | ||
"already registered parameter #{parameter.name.inspect}" | ||
else | ||
@registered_names << parameter.name | ||
end | ||
|
||
@all << parameter | ||
arr = instance_variable_get("@#{parameter.to_sym}s") | ||
arr.send :<<, parameter | ||
end | ||
alias add << | ||
end # Parameters | ||
end # Option | ||
end # TTY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters