Module: BracketErrorSuggestion::BracketAccess
- Defined in:
- lib/bracket_error_suggestion/bracket_access.rb
Instance Attribute Summary collapse
-
#path_on_be_suggestion ⇒ Object
Returns the value of attribute path_on_be_suggestion.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#path_on_be_suggestion ⇒ Object
Returns the value of attribute path_on_be_suggestion.
15 16 17 |
# File 'lib/bracket_error_suggestion/bracket_access.rb', line 15 def path_on_be_suggestion @path_on_be_suggestion end |
Class Method Details
.included(klass) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/bracket_error_suggestion/bracket_access.rb', line 7 def included(klass) klass.module_eval do alias_method :_get_without_be_suggestion, :[] alias_method :[], :_get_with_be_suggestion end end |
Instance Method Details
#_actual_path_on_be_suggestion ⇒ Object
37 38 39 |
# File 'lib/bracket_error_suggestion/bracket_access.rb', line 37 def _actual_path_on_be_suggestion path_on_be_suggestion || "<#{self.class.name}>" end |
#_get_with_be_suggestion(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bracket_error_suggestion/bracket_access.rb', line 17 def _get_with_be_suggestion(name) if BracketErrorSuggestion.enabled begin r = _get_without_be_suggestion(name) rescue TypeError => e raise TypeError, "#{e.message}, it attempted to access #{_actual_path_on_be_suggestion}[#{name.inspect}] but #{_actual_path_on_be_suggestion} is an Array" end return r unless BracketErrorSuggestion.enabled case r when nil then BracketErrorSuggestion.nil_parent_paths << "#{_actual_path_on_be_suggestion}[#{name.inspect}]" when Array, Hash then r.path_on_be_suggestion ||= "#{_actual_path_on_be_suggestion}[#{name.inspect}]" end return r else return _get_without_be_suggestion(name) end end |