class Hanami::Extensions::View::SliceConfiguredContext

Provides slice-specific configuration and behavior for any view context class defined within a slice’s module namespace.

@api public @since 2.1.0

Attributes

slice[R]

Public Class Methods

new(slice) click to toggle source

@api private @since 2.1.0

Calls superclass method
# File lib/hanami/extensions/view/slice_configured_context.rb, line 16
def initialize(slice)
  super()
  @slice = slice
end

Public Instance Methods

extended(_context_class) click to toggle source

@api private @since 2.1.0

# File lib/hanami/extensions/view/slice_configured_context.rb, line 23
def extended(_context_class)
  define_new
end
inspect() click to toggle source

@api public @since 2.1.0

# File lib/hanami/extensions/view/slice_configured_context.rb, line 29
def inspect
  "#<#{self.class.name}[#{slice.name}]>"
end

Private Instance Methods

define_new() click to toggle source

Defines a {.new} method on the context class that resolves key components from the app container and provides them to {#initialize} as injected dependencies.

This includes the following app components:

- the configured inflector as `inflector`
- "settings" from the app container as `settings`
- "routes" from the app container as `routes`
- "assets" from the app container as `assets`
Calls superclass method
# File lib/hanami/extensions/view/slice_configured_context.rb, line 43
def define_new
  inflector = slice.inflector
  resolve_settings = method(:resolve_settings)
  resolve_routes = method(:resolve_routes)
  resolve_assets = method(:resolve_assets)

  define_method :new do |**kwargs|
    kwargs[:inflector] ||= inflector
    kwargs[:settings] ||= resolve_settings.()
    kwargs[:routes] ||= resolve_routes.()
    kwargs[:assets] ||= resolve_assets.()

    super(**kwargs)
  end
end
resolve_assets() click to toggle source
# File lib/hanami/extensions/view/slice_configured_context.rb, line 67
def resolve_assets
  slice["assets"] if slice.key?("assets")
end
resolve_routes() click to toggle source
# File lib/hanami/extensions/view/slice_configured_context.rb, line 63
def resolve_routes
  slice["routes"] if slice.key?("routes")
end
resolve_settings() click to toggle source
# File lib/hanami/extensions/view/slice_configured_context.rb, line 59
def resolve_settings
  slice["settings"] if slice.key?("settings")
end