Module: Hanami::Application::ClassMethods Private

Defined in:
lib/hanami/application.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.

Class interface for Hanami applications

Since:

  • 0.9.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ 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.

Override Ruby’s Class#extended



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hanami/application.rb', line 61

def self.extended(base) # rubocop:disable Metrics/MethodLength
  super

  base.class_eval do
    @namespace      = ApplicationNamespace.resolve(name)
    @configurations = EnvironmentApplicationConfigurations.new
    @_lock          = Mutex.new

    class << self
      # @since 0.9.0
      # @api private
      attr_reader :namespace

      # @since 0.9.0
      # @api private
      attr_reader :configurations

      # @since 0.9.0
      # @api private
      attr_reader :configuration
    end
  end
end

Instance Method Details

#app_nameString

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.

Hanami application name

Examples:

require 'hanami'

module Web
  class Application < Hanami::Application
  end
end

Web::Application.app_name # => "web"

Returns:

  • (String)

    the Hanami application name

Since:

  • 0.9.0



101
102
103
# File 'lib/hanami/application.rb', line 101

def app_name
  ApplicationName.new(name).to_s
end

#configuration=(configuration) ⇒ 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.

Set configuration

Parameters:

Raises:

  • (RuntimeError)

    if the configuration is assigned more than once

Since:

  • 0.1.0



113
114
115
116
117
118
# File 'lib/hanami/application.rb', line 113

def configuration=(configuration)
  @_lock.synchronize do
    # raise "Can't assign configuration more than once (#{app_name})" unless @configuration.nil?
    @configuration = configuration
  end
end

#configure(environment = nil, &blk) ⇒ 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.

Configure the application. It yields the given block in the context of the configuration

Examples:

require 'hanami'

module Bookshelf
  Application < Hanami::Application
    configure do
      # ...
    end
  end
end

Parameters:

  • environment (Symbol, nil) (defaults to: nil)

    the configuration environment name

  • blk (Proc)

    the configuration block

See Also:

Since:

  • 0.1.0



140
141
142
# File 'lib/hanami/application.rb', line 140

def configure(environment = nil, &blk)
  configurations.add(environment, &blk)
end