Class: Hanami::ApplicationName Private
- Inherits:
-
Object
- Object
- Hanami::ApplicationName
- 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.
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
%w(hanami).freeze
Class Method Summary collapse
-
.invalid?(name) ⇒ TrueClass, FalseClass
private
Returns true if a potential application name matches one of the reserved words.
Instance Method Summary collapse
-
#initialize(name) ⇒ Hanami::ApplicationName
constructor
private
Initialize and check against reserved words.
-
#to_env_s ⇒ String
private
Returns the application name uppercased with non-alphanumeric characters as underscores.
-
#to_s ⇒ String
(also: #to_str)
private
Returns the cleaned application name.
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:
-
downcased,
-
with surrounding spaces removed,
-
with internal whitespace rendered as underscores
-
with underscores de-duplicated
which is the default output. It must also be transformable into an environment variable.
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.
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_s ⇒ String
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.
67 68 69 |
# File 'lib/hanami/application_name.rb', line 67 def to_env_s @name.upcase.gsub(/\W/, '_') end |
#to_s ⇒ String 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.
49 50 51 |
# File 'lib/hanami/application_name.rb', line 49 def to_s @name end |