Class: EnsureIt::ErrorMessage
- Inherits:
-
Object
- Object
- EnsureIt::ErrorMessage
- Defined in:
- lib/ensure_it/errors.rb
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#inside ⇒ Object
Returns the value of attribute inside.
- #message ⇒ Object
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#subject_type ⇒ Object
Returns the value of attribute subject_type.
Instance Method Summary collapse
-
#initialize(method_name, message, backtrace) ⇒ ErrorMessage
constructor
A new instance of ErrorMessage.
- #subject_display_name ⇒ Object
Constructor Details
#initialize(method_name, message, backtrace) ⇒ ErrorMessage
Returns a new instance of ErrorMessage.
8 9 10 11 12 13 14 |
# File 'lib/ensure_it/errors.rb', line 8 def initialize(method_name, , backtrace) method_name = method_name.to_sym if method_name.is_a?(String) unless method_name.is_a?(Symbol) raise ArgumentError, 'EnsureIt: Wrong method_name argument for Error' end @method_name, @message, @backtrace = method_name, , backtrace end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
5 6 7 |
# File 'lib/ensure_it/errors.rb', line 5 def backtrace @backtrace end |
#inside ⇒ Object
Returns the value of attribute inside.
5 6 7 |
# File 'lib/ensure_it/errors.rb', line 5 def inside @inside end |
#message ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ensure_it/errors.rb', line 47 def unless @message.is_a?(String) @message = if @subject.nil? && @subject_type != :unknown_method_result '#{subject}' else '#{subject} of #{method_name}' end end @message.gsub(/\#\{subject\}/, subject_display_name) .gsub(/\#\{name\}/, @subject.to_s) .gsub(/\#\{method_name\}/, @method_name.to_s) end |
#method_name ⇒ Object
Returns the value of attribute method_name.
5 6 7 |
# File 'lib/ensure_it/errors.rb', line 5 def method_name @method_name end |
#subject ⇒ Object
Returns the value of attribute subject.
5 6 7 |
# File 'lib/ensure_it/errors.rb', line 5 def subject @subject end |
#subject_type ⇒ Object
Returns the value of attribute subject_type.
5 6 7 |
# File 'lib/ensure_it/errors.rb', line 5 def subject_type @subject_type end |
Instance Method Details
#subject_display_name ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ensure_it/errors.rb', line 16 def subject_display_name display_name = if @subject.nil? && @subject_type != :unknown_method_result "subject of '#{method_name}' method" else case @subject_type when :local_variable then "local variable '#{@subject}'" when :instance_variable then "instance variable '@#{@subject}'" when :class_variable then "class variable '@@#{@subject}'" when :method_result then "return value of '#{subject}' method" when :unknown_method_result then 'return value of method' when :req_argument then "argument '#{subject}'" when :rest_argument then "argument '*#{subject}'" when :opt_argument then "optional argument '#{subject}'" when :key_argument then "key argument '#{subject}'" when :keyrest_argument then "key argument '**#{subject}'" when :block_argument then "block argument '&#{subject}'" else "subject of '#{method_name}' method" end end unless @inside.nil? display_name += if !@subject_type.nil? && @subject_type.to_s =~ /_argument\z/ " of '#{@inside}' method" else " inside '#{@inside}' method" end end display_name end |