Exception: InstantCache::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
lib/instantcache/exceptions.rb

Overview

The superclass for all of the InstantCache exceptions. It provides all the infrastructure needed by the individual specific exceptions.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Exception

Description

As the superclass, this exception is not intended for direct invocation.

Arguments

N/A

Exceptions

InstantCache::IncompleteException

This class was subclassed, but the subclass didn’t declare the requisite MessageFormat constant.



70
71
72
73
74
75
76
# File 'lib/instantcache/exceptions.rb', line 70

def initialize(*args)
  @appargs = args.dup
  super(args[0])
  unless (self.class.constants.include?('MessageFormat'))
    raise IncompleteException.new(self.class.name)
  end
end

Instance Method Details

#messageObject

Description

This is an override of the standard exception message method, enhanced to deal with our with-or-without-arguments invocation decision mechanism.

If the current class has a MessageFormat constant array defined, the first element will be used for the exception message if no arguments were passed to the invocation. Otherwise, the second element of the MessageFormat array will be treated as a ‘%’ format string and the invocation arguments as input to the formatting process, the result of which becomes the exception message string.

Arguments

None.

Exceptions

None.



98
99
100
101
102
103
104
# File 'lib/instantcache/exceptions.rb', line 98

def message
  if (self.class.constants.include?('MessageFormat'))
    fmt = self.class::MessageFormat[@appargs.empty? ? 0 : 1]
    return fmt % [ *@appargs ]
  end
  return @message
end

#to_sObject

Description

Return the message text of the exception as a string, after applying any appropriate formating.

Arguments

None.

Exceptions

None.



117
118
119
# File 'lib/instantcache/exceptions.rb', line 117

def to_s
  return self.message
end