Exception: Safer::Protocol::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/safer/protocol.rb

Overview

Error generated when a class does not conform to a protocol signature.

Direct Known Subclasses

ClassError, InstanceError

Defined Under Namespace

Classes: ClassError, InstanceError

Instance Method Summary collapse

Constructor Details

#initialize(message, error_object, protocol, class_violations, instance_violations) ⇒ Error

Create a Safer::Protocol::Error object. Used internally.



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/safer/protocol.rb', line 273

def initialize(message, error_object, protocol, class_violations, instance_violations)
  super(message)
  self.safer_protocol_error__error_object = error_object
  self.safer_protocol_error__protocol = protocol
  self.safer_protocol_error__class_violations = class_violations
  self.safer_protocol_error__instance_violations = instance_violations
  report = ''
  if class_violations
    report +=
      "Class method errors:\n" +
      self.safer_protocol_error__class_violations.report
    if instance_violations
      report += "\n\n"
    end
  end
  if instance_violations
    report +=
      "Instance method errors:\n" +
      self.safer_protocol_error__instance_violations.report
  end
  self.safer_protocol_error__report = report
end

Instance Method Details

#==(other_object) ⇒ Object

Compare two Safer::Protocol::Error objects for content equality.



298
299
300
301
302
303
304
# File 'lib/safer/protocol.rb', line 298

def ==(other_object)
  self.class == other_object.class &&
    self.error_object == other_object.error_object &&
    self.protocol == other_object.protocol &&
    self.class_violations == other_object.class_violations &&
    self.instance_violations == other_object.instance_violations
end

#selfObject

:attr_reader: report String for displaying human-readable error message describing protocol violations.



249
# File 'lib/safer/protocol.rb', line 249

Safer::IVar.export_reader(self, :error_object)