Module: Hanami::SliceConfigurable Private
- Included in:
- Extensions::View::PartHelpers
- Defined in:
- lib/hanami/slice_configurable.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Calls ‘configure_for_slice(slice)` on the extended class whenever it is first subclassed within a module namespace corresponding to a slice.
Class Method Summary collapse
- .extended(klass) ⇒ Object private
Instance Method Summary collapse
- #configure_for_slice(slice) ⇒ Object private
- #configured_for_slice?(slice) ⇒ Boolean private
- #configured_for_slices ⇒ Object private
Class Method Details
.extended(klass) ⇒ 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hanami/slice_configurable.rb', line 29 def extended(klass) slice_for = method(:slice_for) inherited_mod = Module.new do define_method(:inherited) do |subclass| unless Hanami.app? raise ComponentLoadError, "Class #{klass} must be defined within an Hanami app" end super(subclass) subclass.instance_variable_set(:@configured_for_slices, configured_for_slices.dup) slice = slice_for.(subclass) return unless slice unless subclass.configured_for_slice?(slice) subclass.configure_for_slice(slice) subclass.configured_for_slices << slice end end end klass.singleton_class.prepend(inherited_mod) end |
Instance Method Details
#configure_for_slice(slice) ⇒ 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.
66 |
# File 'lib/hanami/slice_configurable.rb', line 66 def configure_for_slice(slice); end |
#configured_for_slice?(slice) ⇒ Boolean
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.
68 69 70 |
# File 'lib/hanami/slice_configurable.rb', line 68 def configured_for_slice?(slice) configured_for_slices.include?(slice) end |
#configured_for_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.
72 73 74 |
# File 'lib/hanami/slice_configurable.rb', line 72 def configured_for_slices @configured_for_slices ||= [] end |