Class: Mutant::CLI::Classifier
- Inherits:
-
Object
- Object
- Mutant::CLI::Classifier
- Includes:
- AbstractType, Adamantium::Flat
- Defined in:
- lib/mutant/cli/classifier.rb,
lib/mutant/cli/classifier/method.rb,
lib/mutant/cli/classifier/namespace.rb
Overview
A classifier for input strings
Defined Under Namespace
Constant Summary collapse
- SCOPE_NAME_PATTERN =
/[A-Za-z][A-Za-z\d_]*/.freeze
- SCOPE_OPERATOR =
'::'.freeze
- CBASE_PATTERN =
/\A#{SCOPE_OPERATOR}/.freeze
- METHOD_NAME_PATTERN =
Regexp.union( /[A-Za-z_][A-Za-z\d_]*[!?=]?/, *OPERATOR_METHODS.map(&:to_s) ).freeze
- SCOPE_PATTERN =
/ (?:#{SCOPE_OPERATOR})?#{SCOPE_NAME_PATTERN} (?:#{SCOPE_OPERATOR}#{SCOPE_NAME_PATTERN})* /x.freeze
- REGISTRY =
{}
Class Method Summary collapse
-
.constant_lookup(location) ⇒ Class|Module
private
Return constant.
-
.run(cache, pattern) ⇒ Matcher
private
Return matchers for input.
Instance Method Summary collapse
-
#each(&block) ⇒ self, Enumerator<Subject>
private
Enumerate subjects.
-
#identifier ⇒ String
private
Return identifier.
Class Method Details
.constant_lookup(location) ⇒ Class|Module
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return constant
46 47 48 49 50 51 |
# File 'lib/mutant/cli/classifier.rb', line 46 def self.constant_lookup(location) location.sub(CBASE_PATTERN, EMPTY_STRING).split(SCOPE_OPERATOR) .reduce(Object) do |parent, name| parent.const_get(name, nil) end end |
.run(cache, pattern) ⇒ Matcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return matchers for input
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mutant/cli/classifier.rb', line 66 def self.run(cache, pattern) matches = find(pattern) case matches.length when 0 raise Error, "No matcher handles: #{pattern.inspect}" when 1 klass, match = matches.first klass.new(cache, match).matcher else raise Error, "More than one matcher found for: #{pattern.inspect}" end end |
Instance Method Details
#each(&block) ⇒ self, Enumerator<Subject>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enumerate subjects
105 106 107 108 109 |
# File 'lib/mutant/cli/classifier.rb', line 105 def each(&block) return to_enum unless block_given? matcher.each(&block) self end |
#identifier ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return identifier
117 118 119 |
# File 'lib/mutant/cli/classifier.rb', line 117 def identifier match.to_s end |