Class: Hanami::ApplicationName Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/application_name.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An application name.

Since:

  • 0.2.1

Constant Summary collapse

RESERVED_WORDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A list of words that are prohibited from forming the application name

Since:

  • 0.2.1

%w(hanami).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Hanami::ApplicationName

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize and check against reserved words

An application name needs to be translated in quite a few ways: First, it must be checked against a list of reserved words and rejected if it is invalid. Secondly, assuming it is not invalid, it must be able to be output roughly as given, but with the following changes:

  1. downcased,

  2. with surrounding spaces removed,

  3. with internal whitespace rendered as underscores

  4. with underscores de-duplicated

which is the default output. It must also be transformable into an environment variable.

Since:

  • 0.2.1



35
36
37
38
# File 'lib/hanami/application_name.rb', line 35

def initialize(name)
  @name = sanitize(name.to_s)
  ensure_validity!
end

Class Method Details

.invalid?(name) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if a potential application name matches one of the reserved words.

Examples:

Hanami::ApplicationName.invalid?("hanami") # => true

Parameters:

  • name (String)

    the application name

Returns:

  • (TrueClass, FalseClass)

    the result of the check

Since:

  • 0.2.1



82
83
84
# File 'lib/hanami/application_name.rb', line 82

def self.invalid?(name)
  RESERVED_WORDS.include?(name)
end

Instance Method Details

#to_env_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the application name uppercased with non-alphanumeric characters as underscores.

Examples:

ApplicationName.new("my-app").to_env_s => "MY_APP"

Returns:

  • (String)

    the upcased name

Since:

  • 0.2.1



67
68
69
# File 'lib/hanami/application_name.rb', line 67

def to_env_s
  @name.upcase.gsub(/\W/, '_')
end

#to_sString Also known as: to_str

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the cleaned application name.

Examples:

ApplicationName.new("my-App ").to_s # => "my_app"

Returns:

  • (String)

    the sanitized name

Since:

  • 0.2.1



49
50
51
# File 'lib/hanami/application_name.rb', line 49

def to_s
  @name
end