Class: SpecForge::Error::InvalidInvocationError

Inherits:
Error
  • Object
show all
Defined in:
lib/spec_forge/error.rb

Overview

Raised when a step in an invocation chain is invalid Provides detailed information about where in the chain the error occurred

Examples:

variable_attr = Attribute::Variable.new("variables.user.invalid_method")
variable_attr.resolved
# => InvalidInvocationError: Cannot invoke "invalid_method" on User

Instance Method Summary collapse

Constructor Details

#initialize(step, object, resolution_path = {}) ⇒ InvalidInvocationError

Returns a new instance of InvalidInvocationError.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/spec_forge/error.rb', line 105

def initialize(step, object, resolution_path = {})
  @step = step
  @object = object
  @resolution_path = resolution_path

  object_class =
    case object
    when Data
      object.class.name || "Data"
    when Struct
      object.class.name || "Struct"
    else
      object.class
    end

  super(<<~STRING.chomp
    Cannot invoke "#{step}" on #{object_class}
    #{resolution_path_message}
  STRING
  )
end

Instance Method Details

#with_resolution_path(path) ⇒ Object

Creates a new InvalidInvocationError with a new resolution path

Parameters:

  • path (Hash)

    The steps taken up until this point



132
133
134
# File 'lib/spec_forge/error.rb', line 132

def with_resolution_path(path)
  self.class.new(@step, @object, path)
end