Class: Hanami::SliceName
- Inherits:
-
Object
- Object
- Hanami::SliceName
- Defined in:
- lib/hanami/slice_name.rb
Overview
Instance Method Summary collapse
-
#initialize(slice, inflector:) ⇒ SliceName
constructor
private
Returns a new SliceName for the slice or app.
-
#name ⇒ String
(also: #path, #to_s)
Returns the name of the slice as a downcased, underscored string.
-
#namespace_const ⇒ Module
(also: #namespace)
Returns the constant for the slice’s module namespace.
-
#namespace_name ⇒ String
Returns the name of the slice’s module namespace.
-
#to_sym ⇒ Symbol
Returns the name of a slice as a downcased, underscored symbol.
Constructor Details
#initialize(slice, inflector:) ⇒ SliceName
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 a new SliceName for the slice or app.
You must provide an inflector for the manipulation of the name into various formats. This should be given in the form of a Proc that returns the inflector when called. The reason for this is that the inflector may be replaced by the user during the app configuration phase, so the proc should ensure that the current instance of the inflector is returned whenever needed.
26 27 28 29 |
# File 'lib/hanami/slice_name.rb', line 26 def initialize(slice, inflector:) @slice = slice @inflector = inflector end |
Instance Method Details
#name ⇒ String Also known as: path, to_s
Returns the name of the slice as a downcased, underscored string.
This is considered the canonical name of the slice.
42 43 44 |
# File 'lib/hanami/slice_name.rb', line 42 def name inflector.underscore(namespace_name) end |
#namespace_const ⇒ Module Also known as: namespace
Returns the constant for the slice’s module namespace.
72 73 74 |
# File 'lib/hanami/slice_name.rb', line 72 def namespace_const inflector.constantize(namespace_name) end |
#namespace_name ⇒ String
Returns the name of the slice’s module namespace.
59 60 61 |
# File 'lib/hanami/slice_name.rb', line 59 def namespace_name slice_name.split(MODULE_DELIMITER)[0..-2].join(MODULE_DELIMITER) end |
#to_sym ⇒ Symbol
Returns the name of a slice as a downcased, underscored symbol.
95 96 97 |
# File 'lib/hanami/slice_name.rb', line 95 def to_sym name.to_sym end |