Class: DidYouMean::ClassFinder
- Inherits:
-
Object
- Object
- DidYouMean::ClassFinder
- Includes:
- BaseFinder
- Defined in:
- lib/did_you_mean/finders/name_error_finders/class_finder.rb
Constant Summary
Constants included from BaseFinder
BaseFinder::AT, BaseFinder::EMPTY
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#original_message ⇒ Object
readonly
Returns the value of attribute original_message.
Instance Method Summary collapse
- #class_names ⇒ Object
-
#initialize(exception) ⇒ ClassFinder
constructor
A new instance of ClassFinder.
-
#name_from_message ⇒ Object
Always use the original error message to retrieve the user input since JRuby 1.7 behaves differently from MRI/Rubinius.
- #scopes ⇒ Object
- #searches ⇒ Object
- #suggestions ⇒ Object
Constructor Details
#initialize(exception) ⇒ ClassFinder
Returns a new instance of ClassFinder.
8 9 10 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 8 def initialize(exception) @class_name, @original_message = exception.name, exception. end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
6 7 8 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 6 def class_name @class_name end |
#original_message ⇒ Object (readonly)
Returns the value of attribute original_message.
6 7 8 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 6 def @original_message end |
Instance Method Details
#class_names ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 16 def class_names scopes.flat_map do |scope| scope.constants.map do |c| ClassName.new(c, scope == Object ? EMPTY : "#{scope}::") end end end |
#name_from_message ⇒ Object
Always use the original error message to retrieve the user input since JRuby 1.7 behaves differently from MRI/Rubinius.
class Name; end
error = (Name::DoesNotExist rescue $!)
# on MRI/Rubinius
error.name #=> :DoesNotExist
# on JRuby <= 1.7
error.name #=> :'Name::DoesNotExist'
37 38 39 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 37 def /([A-Z]\w*$)/.match()[0] end |
#scopes ⇒ Object
50 51 52 53 54 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 50 def scopes @scopes ||= scope_base.inject([Object]) do |_scopes, scope| _scopes << _scopes.last.const_get(scope) end end |
#searches ⇒ Object
12 13 14 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 12 def searches { => class_names} end |
#suggestions ⇒ Object
46 47 48 |
# File 'lib/did_you_mean/finders/name_error_finders/class_finder.rb', line 46 def suggestions super.map(&:full_name) end |