Class: Lotus::ApplicationName

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

Overview

An application name.

Since:

  • 0.2.1

Constant Summary collapse

RESERVED_WORDS =

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

Since:

  • 0.2.1

%w(lotus).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Lotus::ApplicationName

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



30
31
32
33
# File 'lib/lotus/application_name.rb', line 30

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

Class Method Details

.invalid?(name) ⇒ TrueClass, FalseClass

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

Examples:

Lotus::ApplicationName.invalid?("lotus") # => true

Parameters:

  • name (String)

    the application name

Returns:

  • (TrueClass, FalseClass)

    the result of the check

Since:

  • 0.2.1



70
71
72
# File 'lib/lotus/application_name.rb', line 70

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

Instance Method Details

#to_env_sString

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



56
57
58
# File 'lib/lotus/application_name.rb', line 56

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

#to_sString

Returns the cleaned application name.

Examples:

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

Returns:

  • (String)

    the santized name

Since:

  • 0.2.1



43
44
45
# File 'lib/lotus/application_name.rb', line 43

def to_s
  @name
end