Class: Hanami::Providers::DB::Gateway

Inherits:
Object
  • Object
show all
Includes:
Dry::Configurable, Dry::Core::Constants
Defined in:
lib/hanami/providers/db/gateway.rb

Overview

Since:

  • 2.2.0

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Since:

  • 2.2.0



73
74
75
76
77
78
79
# File 'lib/hanami/providers/db/gateway.rb', line 73

def method_missing(name, *args, &block)
  if config.respond_to?(name)
    config.public_send(name, *args, &block)
  else
    super
  end
end

Instance Method Details

#adapter(name = Undefined) ⇒ Object

Since:

  • 2.2.0



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hanami/providers/db/gateway.rb', line 22

def adapter(name = Undefined)
  return config.adapter if name.eql?(Undefined)

  if block_given?
    # If a block is given, explicitly configure the gateway's adapter
    config.adapter_name = name
    adapter = (config.adapter ||= Adapters.new_adapter(name))
    yield adapter
    adapter
  else
    # If an adapter name is given without a block, use the default adapter configured with
    # the same name
    config.adapter_name = adapter_name
  end
end

#cache_keysObject

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



67
68
69
# File 'lib/hanami/providers/db/gateway.rb', line 67

def cache_keys
  [config.database_url, config.connection_options, config.adapter.gateway_cache_keys]
end

#configure_adapter(default_adapters) ⇒ 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.

Since:

  • 2.2.0



55
56
57
58
59
60
61
62
63
64
# File 'lib/hanami/providers/db/gateway.rb', line 55

def configure_adapter(default_adapters)
  default_adapter = default_adapters.find(config.adapter_name)
  config.adapter ||= default_adapter.dup

  config.adapter.configure_from_adapter(default_adapter)

  config.adapter.configure_for_database(config.database_url)

  self
end

#connection_options(**options) ⇒ Object

Since:

  • 2.2.0



40
41
42
43
44
45
46
# File 'lib/hanami/providers/db/gateway.rb', line 40

def connection_options(**options)
  if options.any?
    config.connection_options.merge!(options)
  end

  config.connection_options
end

#optionsObject

Since:

  • 2.2.0



50
51
52
# File 'lib/hanami/providers/db/gateway.rb', line 50

def options
  {**connection_options, **config.adapter.gateway_options}
end