Class: Hanami::Providers::DB Private
- Inherits:
-
Hanami::Provider::Source
- Object
- Dry::System::Provider::Source
- Hanami::Provider::Source
- Hanami::Providers::DB
- 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.
Defined Under Namespace
Classes: Adapter, Adapters, Config, Gateway, SQLAdapter
Instance Attribute Summary
Attributes inherited from Hanami::Provider::Source
Instance Method Summary collapse
- #database_urls ⇒ Object private
- #finalize_config ⇒ Object private
-
#initialize ⇒ DB
constructor
private
A new instance of DB.
- #prepare ⇒ Object private
- #start ⇒ Object private
- #stop ⇒ Object private
Methods inherited from Hanami::Provider::Source
Constructor Details
#initialize ⇒ DB
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.
20 21 22 23 24 |
# File 'lib/hanami/providers/db.rb', line 20 def initialize(...) super(...) @config_finalized = false end |
Instance Method Details
#database_urls ⇒ 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.
96 97 98 99 |
# File 'lib/hanami/providers/db.rb', line 96 def database_urls finalize_config config.gateways.transform_values { _1.database_url } end |
#finalize_config ⇒ 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.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hanami/providers/db.rb', line 26 def finalize_config return if @config_finalized apply_parent_config if apply_parent_config? configure_gateways @config_finalized = true self end |
#prepare ⇒ 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.
38 39 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 |
# File 'lib/hanami/providers/db.rb', line 38 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 |
#start ⇒ 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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hanami/providers/db.rb', line 73 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 |
#stop ⇒ 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.
90 91 92 |
# File 'lib/hanami/providers/db.rb', line 90 def stop slice["db.rom"].disconnect end |