Module: Hanami::Application::ClassMethods

Defined in:
lib/hanami/application.rb

Overview

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


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/hanami/application.rb', line 73

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


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

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


125
126
127
128
129
130
# File 'lib/hanami/application.rb', line 125

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

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


152
153
154
# File 'lib/hanami/application.rb', line 152

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