Module: Hanami::Console::Plugins::UnbootedSliceWarnings Private

Defined in:
lib/hanami/console/plugins/unbooted_slice_warnings.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.

Console plugin that prints a one-time warning when an unbooted slice is asked for its .keys.

Since:

  • 2.0.0

Defined Under Namespace

Modules: SliceExtension

Class Method Summary collapse

Class Method Details

.activateObject

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.

Since:

  • 2.0.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hanami/console/plugins/unbooted_slice_warnings.rb', line 14

def self.activate
  warning_shown_for_slice = {}

  # Define the wrapper method with access to the context via closure
  SliceExtension.define_method(:keys) do
    if !booted? && !warning_shown_for_slice[self]
      message = "        Warning: \#{self} is not booted. Run `\#{self}.boot` to load all components, or launch the console with `--boot`.\n      TEXT\n      warn message\n\n      warning_shown_for_slice[self] = true\n    end\n\n    super()\n  end\n\n  Hanami::Slice::ClassMethods.prepend(SliceExtension)\nend\n"

.deactivateObject

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.

Since:

  • 2.0.0



34
35
36
# File 'lib/hanami/console/plugins/unbooted_slice_warnings.rb', line 34

def self.deactivate
  SliceExtension.remove_method :keys
end