lib/hanami/application_name.rb in hanami-1.0.0.beta2 vs lib/hanami/application_name.rb in hanami-1.0.0.beta3

- old
+ new

@@ -2,15 +2,17 @@ module Hanami # An application name. # # @since 0.2.1 + # @api private class ApplicationName # A list of words that are prohibited from forming the application name # # @since 0.2.1 + # @api private RESERVED_WORDS = %w(hanami).freeze # Initialize and check against reserved words # # An application name needs to be translated in quite a few ways: @@ -27,10 +29,11 @@ # environment variable. # # @return [Hanami::ApplicationName] a new instance of the application name # # @since 0.2.1 + # @api private def initialize(name) @name = sanitize(name.to_s) ensure_validity! end @@ -40,10 +43,11 @@ # # @example # ApplicationName.new("my-App ").to_s # => "my_app" # # @since 0.2.1 + # @api private def to_s @name end # @api private @@ -57,10 +61,11 @@ # # @example # ApplicationName.new("my-app").to_env_s => "MY_APP" # # @since 0.2.1 + # @api private def to_env_s @name.upcase.gsub(/\W/, '_') end # Returns true if a potential application name matches one of the reserved @@ -71,31 +76,32 @@ # # @example # Hanami::ApplicationName.invalid?("hanami") # => true # # @since 0.2.1 + # @api private def self.invalid?(name) RESERVED_WORDS.include?(name) end private # Raises RuntimeError with explanation if the provided name is invalid. # - # @api private # @since 0.2.1 + # @api private def ensure_validity! if self.class.invalid?(@name) raise RuntimeError, "application name must not be any one of the following: " + RESERVED_WORDS.join(", ") end end # Cleans a string to be a functioning application name. # - # @api private # @since 0.2.1 + # @api private def sanitize(name) Utils::String.new( name.strip ).namespace.underscore.to_s end