Class: Hanami::Providers::DB Private

Inherits:
Hanami::Provider::Source show all
Extended by:
Dry::Core::Cache
Defined in:
lib/hanami/providers/db.rb,
lib/hanami/providers/db/config.rb,
lib/hanami/providers/db/adapter.rb,
lib/hanami/providers/db/gateway.rb,
lib/hanami/providers/db/adapters.rb,
lib/hanami/providers/db/sql_adapter.rb

Overview

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.

Since:

  • 2.2.0

API:

  • private

Defined Under Namespace

Classes: Adapter, Adapters, Config, Gateway, SQLAdapter

Instance Attribute Summary

Attributes inherited from Hanami::Provider::Source

#slice

Instance Method Summary collapse

Methods inherited from Hanami::Provider::Source

#target_container

Constructor Details

#initializeDB

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 DB.

Since:

  • 2.2.0

API:

  • private



22
23
24
25
26
# File 'lib/hanami/providers/db.rb', line 22

def initialize(...)
  super(...)

  @config_finalized = false
end

Instance Method Details

#database_urlsObject

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:

  • 2.2.0

API:

  • private



98
99
100
101
# File 'lib/hanami/providers/db.rb', line 98

def database_urls
  finalize_config
  config.gateways.transform_values { _1.database_url }
end

#finalize_configObject

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:

  • 2.2.0

API:

  • private



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hanami/providers/db.rb', line 28

def finalize_config
  return if @config_finalized

  apply_parent_config if apply_parent_config?

  configure_gateways

  @config_finalized = true

  self
end

#prepareObject

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:

  • 2.2.0

API:

  • private



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hanami/providers/db.rb', line 40

def prepare
  prepare_and_import_parent_db and return if import_from_parent?

  override_rom_inflector

  finalize_config

  require "hanami-db"

  gateways = prepare_gateways

  if gateways[:default]
    register "gateway", gateways[:default]
  elsif gateways.length == 1
    register "gateway", gateways.values.first
  end
  gateways.each do |key, gateway|
    register "gateways.#{key}", gateway
  end

  @rom_config = ROM::Configuration.new(gateways)

  config.each_plugin do |adapter_name, plugin_spec, config_block|
    if config_block
      @rom_config.plugin(adapter_name, plugin_spec) do |plugin_config|
        instance_exec(plugin_config, &config_block)
      end
    else
      @rom_config.plugin(adapter_name, plugin_spec)
    end
  end

  register "config", @rom_config
end

#startObject

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:

  • 2.2.0

API:

  • private



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/hanami/providers/db.rb', line 75

def start
  start_and_import_parent_db and return if import_from_parent?

  # Set up DB logging for the whole app. We share the app's notifications bus across all
  # slices, so we only need to configure the subsciprtion for DB logging just once.
  slice.app.start :db_logging

  # Register ROM components
  register_rom_components :relation, "relations"
  register_rom_components :command, File.join("db", "commands")
  register_rom_components :mapper, File.join("db", "mappers")

  rom = ROM.container(@rom_config)

  register "rom", rom
end

#stopObject

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:

  • 2.2.0

API:

  • private



92
93
94
# File 'lib/hanami/providers/db.rb', line 92

def stop
  slice["db.rom"].disconnect
end