Class: Hanami::SliceRegistrar Private
- Inherits:
-
Object
- Object
- Hanami::SliceRegistrar
- Defined in:
- lib/hanami/slice_registrar.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.
Constant Summary collapse
- VALID_SLICE_NAME_RE =
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-z][a-z0-9_]+$/
- SLICE_DELIMITER =
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.
CONTAINER_KEY_DELIMITER
Instance Method Summary collapse
- #[](name) ⇒ Object private
- #each(&block) ⇒ Object private
- #freeze ⇒ Object private
-
#initialize(parent) ⇒ SliceRegistrar
constructor
private
A new instance of SliceRegistrar.
- #keys ⇒ Object private
- #load_slices ⇒ Object private
- #register(name, slice_class = nil, &block) ⇒ Object private
- #to_a ⇒ Object private
- #with_nested ⇒ Object private
Constructor Details
#initialize(parent) ⇒ SliceRegistrar
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 instance of SliceRegistrar.
14 15 16 17 |
# File 'lib/hanami/slice_registrar.rb', line 14 def initialize(parent) @parent = parent @slices = {} end |
Instance Method Details
#[](name) ⇒ Object
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.
37 38 39 40 41 |
# File 'lib/hanami/slice_registrar.rb', line 37 def [](name) slices.fetch(name) do raise SliceLoadError, "Slice '#{name}' not found" end end |
#each(&block) ⇒ Object
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.
63 64 65 |
# File 'lib/hanami/slice_registrar.rb', line 63 def each(&block) slices.each_value(&block) end |
#freeze ⇒ Object
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.
43 44 45 46 |
# File 'lib/hanami/slice_registrar.rb', line 43 def freeze slices.freeze super end |
#keys ⇒ Object
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.
67 68 69 |
# File 'lib/hanami/slice_registrar.rb', line 67 def keys slices.keys end |
#load_slices ⇒ Object
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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hanami/slice_registrar.rb', line 48 def load_slices slice_configs = root.join(CONFIG_DIR, SLICES_DIR).glob("*#{RB_EXT}") .map { _1.basename(RB_EXT) } slice_dirs = root.join(SLICES_DIR).glob("*") .select(&:directory?) .map { _1.basename } (slice_dirs + slice_configs).uniq.sort .then { filter_slice_names(_1) } .each(&method(:load_slice)) self end |
#register(name, slice_class = nil, &block) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hanami/slice_registrar.rb', line 19 def register(name, slice_class = nil, &block) unless name.to_s =~ VALID_SLICE_NAME_RE raise ArgumentError, "slice name #{name.inspect} must be lowercase alphanumeric text and underscores only" end return unless filter_slice_names([name]).any? if slices.key?(name.to_sym) raise SliceLoadError, "Slice '#{name}' is already registered" end slice = slice_class || build_slice(name, &block) configure_slice(name, slice) slices[name.to_sym] = slice end |
#to_a ⇒ Object
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.
71 72 73 |
# File 'lib/hanami/slice_registrar.rb', line 71 def to_a slices.values end |
#with_nested ⇒ Object
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.
75 76 77 78 79 80 81 |
# File 'lib/hanami/slice_registrar.rb', line 75 def with_nested to_a.flat_map { |slice| # Return nested slices first so that their more specific namespaces may be picked up first # by SliceConfigurable#slice_for slice.slices.with_nested + [slice] } end |