Class: Hanami::Config

Inherits:
Object show all
Includes:
Dry::Configurable
Defined in:
gems/gems/hanami-2.1.0/lib/hanami/config.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/views.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/assets.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/logger.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/router.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/actions.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/null_config.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/actions/cookies.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/actions/sessions.rb,
gems/gems/hanami-2.1.0/lib/hanami/config/actions/content_security_policy.rb

Overview

Hanami app config

Since:

  • 2.0.0

Defined Under Namespace

Classes: NullConfig

Constant Summary collapse

SUPPORTED_MIDDLEWARE_PARSERS =

Since:

  • 2.0.0

%i[json].freeze

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Since:

  • 2.0.0

def method_missing(name, *args, &block)
  if config.respond_to?(name)
    config.public_send(name, *args, &block)
  else
    super
  end
end

Instance Method Details

#load_dependent_config(gem_name) ⇒ Object (private)

Since:

  • 2.0.0

def load_dependent_config(gem_name)
  if Hanami.bundled?(gem_name)
    yield
  else
    require_relative "config/null_config"
    NullConfig.new
  end
end

#load_from_envObject (private)

Since:

  • 2.0.0

def load_from_env
  self.slices = ENV["HANAMI_SLICES"]&.split(",")&.map(&:strip)
end

#respond_to_missing?(name, _incude_all = false) ⇒ Boolean (private)

Returns:

Since:

  • 2.0.0

def respond_to_missing?(name, _incude_all = false)
  config.respond_to?(name) || super
end

#use_body_parser_middlewareObject (private)

Since:

  • 2.0.0

def use_body_parser_middleware
  return unless Hanami.bundled?("hanami-controller")

  return if actions.formats.empty?
  return if middleware.stack["/"].map(&:first).any? { |klass| klass == "Hanami::Middleware::BodyParser" }

  parsers = SUPPORTED_MIDDLEWARE_PARSERS & actions.formats.values
  return if parsers.empty?

  middleware.use(
    :body_parser,
    [parsers.to_h { |parser_format|
      [parser_format, actions.formats.mime_types_for(parser_format)]
    }]
  )
end