Sha256: 83ec5d63bf14b8139dcc1d54d8242b0f2831fd80790b2162d6284820ebaa165c

Contents?: true

Size: 973 Bytes

Versions: 7

Compression:

Stored size: 973 Bytes

Contents

class Evil::Client
  #
  # Exception to be risen when selected name cannot be used in a custom client.
  #
  class NameError < ::NameError
    # Checks whether a name is valid
    #
    # @param  [#to_sym] name The name to check
    # @param  [Array<Symbol>] forbidden ([]) The list of forbidden names
    # @return [Symbol] if name is valid
    # @raise  [self] if name isn't valid
    #
    def self.check!(name)
      name = name.to_sym
      return name if name[Names::FORMAT] && !Names::FORBIDDEN.include?(name)
      raise new(name)
    end

    private

    def initialize(name)
      super "Invalid name :#{name}." \
            " It should contain latin letters in the lower case, digits," \
            " and underscores only; have minimum 2 chars;" \
            " start from a letter; end with either letter or digit." \
            " The following names: '#{Names::FORBIDDEN.join("', '")}'" \
            " are already used by Evil::Client."
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
evil-client-3.0.2 lib/evil/client/exceptions/name_error.rb
evil-client-3.0.1 lib/evil/client/exceptions/name_error.rb
evil-client-3.0.0 lib/evil/client/exceptions/name_error.rb
evil-client-2.1.1 lib/evil/client/exceptions/name_error.rb
evil-client-2.1.0 lib/evil/client/exceptions/name_error.rb
evil-client-2.0.0 lib/evil/client/exceptions/name_error.rb
evil-client-1.1.0 lib/evil/client/exceptions/name_error.rb