Sha256: 2dd64797b87e9805dbd516da5436e50440133ed8a5039fc2800a2664c7f0020f

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

require 'insxsync/insx_argument_error'

# Provides a base class that provides all the methods required for custom error handling
class ErrorHandlingIface
  # Wrapper method to raise an INSX_ArgumentError with proper parameters
  # @example Validate a parameter
  #   failValidation if not (param == value)
  def failValidation(trace=caller(1))
    raise InsxArgumentError.new(get_usage, self.class.name, trace)
  end

  # Provides the parent method for returning the usage of the calling method.
  # This method should be overridden in every subclass to setup a usage hash
  # using the method names as the keys and an array of strings as the values.
  # @example Example get_usage child method
  #   def get_usage
  #     if @usage.nil?
  #       init_usage
  #       @usage['new'] = [':paramA => String, :paramB=> String']
  #     end
  #
  #     super
  #   end
  def get_usage
    #if called from the initialize method, the user should see "new"
    sender = caller[2][/`([^']+)'/,1] == 'initialize' ? 'new' : caller[2][/`([^']+)'/,1]

    #search through each method in the hash and load it's usage(s)
    @usage.each_key do |method|
      if method == sender
        return @usage[method]
      end
    end

    @usage[nil]
  end

  # Initializes the usage hash for a instance such that any entries that do not exist
  # return '*** WARNING: Usage not defined ***' as the message
  def init_usage
    @usage = Hash.new(['*** WARNING: Usage not defined ***'])
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
insxsync-1.1.0 lib/insxsync/error_handling_iface.rb
insxsync-1.0.1 lib/insxsync/error_handling_iface.rb
insxsync-1.0.0 lib/insxsync/error_handling_iface.rb
insxsync-0.0.14 lib/insxsync/error_handling_iface.rb
insxsync-0.0.13 lib/insxsync/error_handling_iface.rb
insxsync-0.0.12 lib/insxsync/error_handling_iface.rb
insxsync-0.0.11 lib/insxsync/error_handling_iface.rb
insxsync-0.0.10 lib/insxsync/error_handling_iface.rb
insxsync-0.0.9 lib/insxsync/error_handling_iface.rb
insxsync-0.0.8 lib/insxsync/error_handling_iface.rb
insxsync-0.0.7 lib/insxsync/error_handling_iface.rb
insxsync-0.0.6 lib/insxsync/error_handling_iface.rb
insxsync-0.0.5 lib/insxsync/error_handling_iface.rb
insxsync-0.0.4 lib/insxsync/error_handling_iface.rb
insxsync-0.0.3 lib/insxsync/error_handling_iface.rb
insxsync-0.0.2 lib/insxsync/error_handling_iface.rb
insxsync-0.0.1 lib/insxsync/error_handling_iface.rb