Class: Hanami::Configuration Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/configuration.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: App

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ Configuration

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.

Returns a new instance of Configuration.



23
24
25
26
# File 'lib/hanami/configuration.rb', line 23

def initialize(&blk)
  @settings = Concurrent::Map.new
  instance_eval(&blk)
end

Instance Method Details

#appsObject

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:

  • 0.9.0



112
113
114
115
116
# File 'lib/hanami/configuration.rb', line 112

def apps
  mounted.each_pair do |klass, app|
    yield(app) if klass.ancestors.include?(Hanami::Application)
  end
end

#environment(name) ⇒ 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 settings for the current environment

Examples:

Configure Logging for Different Environments

# config/environment.rb
# ...
Hanami.configure do
  # ...
  environment :development do
    logger level: :debug
  end

  environment :production do
    logger level: :info, formatter: :json
  end
end

Parameters:

  • name (Symbol)

    the name of the Hanami environment

See Also:

Since:

  • 1.0.0



176
177
178
# File 'lib/hanami/configuration.rb', line 176

def environment(name)
  yield if ENV['HANAMI_ENV'] == name.to_s
end

#logger(*options) ⇒ 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 logger

Examples:

Basic Usage

# config/environment.rb
# ...
Hanami.configure do
  # ...
  environment :development do
    logger level: :debug
  end
end

Daily Rotation

# config/environment.rb
# ...
Hanami.configure do
  # ...
  environment :development do
    logger 'daily', level: :debug
  end
end

Parameters:

  • options (Array)

    a set of options

See Also:

Since:

  • 1.0.0



148
149
150
151
152
153
154
# File 'lib/hanami/configuration.rb', line 148

def logger(*options)
  if options.empty?
    settings.fetch(:logger, nil)
  else
    settings[:logger] = options
  end
end

#mailer(&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 mailer

Examples:

# config/environment.rb
# ...
Hanami.configure do
  mailer do
    root 'lib/bookshelf/mailers'

    # See http://hanamirb.org/guides/mailers/delivery
    delivery :test
  end

  # ...
end

Parameters:

  • blk (Proc)

    the mailer configuration

See Also:

  • Mailer.configure


94
95
96
# File 'lib/hanami/configuration.rb', line 94

def mailer(&blk)
  mailer_settings.push(blk) if block_given?
end

#mailer_settingsObject

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:

  • next



100
101
102
# File 'lib/hanami/configuration.rb', line 100

def mailer_settings
  settings.fetch_or_store(:mailers, [])
end

#model(&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 database

Examples:

# config/environment.rb
# ...
Hanami.configure do
  model do
    adapter :sql, ENV['DATABASE_URL']

    migrations 'db/migrations'
    schema     'db/schema.sql'
  end

  # ...
end

Parameters:

  • blk (Proc)

    the database configuration

See Also:

  • Model.configure


67
68
69
70
71
72
73
# File 'lib/hanami/configuration.rb', line 67

def model(&blk)
  if block_given?
    settings.put_if_absent(:model, blk)
  else
    settings.fetch(:model)
  end
end

#mount(app, options) ⇒ 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.

Mount a Hanami::Application or a Rack app

Examples:

# config/environment.rb
# ...
Hanami.configure do
  mount Web::Application, at: '/'

  # ...
end

Parameters:

  • app (#call)

    an application compatible with Rack SPEC

  • options (Hash)

    a set of options

  • :at (Hash)

    a customizable set of options

Since:

  • 0.9.0



44
45
46
# File 'lib/hanami/configuration.rb', line 44

def mount(app, options)
  mounted[app] = App.new(app, options.fetch(:at))
end

#mountedObject

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:

  • 0.9.0



106
107
108
# File 'lib/hanami/configuration.rb', line 106

def mounted
  settings.fetch_or_store(:mounted, {})
end