Class: ROM::Registries::Root

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Includes:
Dry::Core::Memoizable, Enumerable
Defined in:
lib/rom/compat/registries.rb,
lib/rom/registries/root.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Deprecated.


43
44
45
# File 'lib/rom/compat/registries.rb', line 43

def method_missing(name, *args, &block)
  fetch(name) { super }
end

Instance Method Details

#build(key, &block) ⇒ 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.



114
115
116
# File 'lib/rom/registries/root.rb', line 114

def build(key, &block)
  components.(key, &block)
end

#disconnectHash<Symbol=>Gateway>

Disconnect all gateways

Examples:

rom = ROM.setup(:sql, 'sqlite://my_db.sqlite')
rom.relations[:users].insert(name: "Jane")
rom.disconnect

Returns:

  • (Hash<Symbol=>Gateway>)

    a hash with disconnected gateways



186
187
188
# File 'lib/rom/registries/root.rb', line 186

def disconnect
  container.keys.grep(/gateways/).each { |key| self[key].disconnect }
end

#eachObject

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.



139
140
141
# File 'lib/rom/registries/root.rb', line 139

def each
  keys.each { |key| yield(fetch(key)) }
end

#empty?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/rom/registries/root.rb', line 167

def empty?
  keys.empty?
end

#fetch(key, &block) ⇒ Object Also known as: []



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rom/registries/root.rb', line 64

def fetch(key, &block)
  case key
  when Symbol
    fetch("#{namespace}.#{key}", &block)
  when String
    return container[key] if container.key?(key)

    loader&.auto_load_component_file(type, key)

    with_registry(root) { build(key, &block) }.tap { |item|
      container.register(key, item)
    }
  when Array
    with_registry(self) { inferrer.call(key, type, **opts) }
  else
    if key.respond_to?(:to_sym)
      fetch(key.to_sym, &block)
    else
      element_not_found(key)
    end
  end
rescue KeyError
  element_not_found(key)
end

#handlerObject

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.



109
110
111
# File 'lib/rom/registries/root.rb', line 109

def handler
  components.handlers[type]
end

#idsObject

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.



157
158
159
# File 'lib/rom/registries/root.rb', line 157

def ids
  components[type].map(&:id)
end

#infer(id, **options) ⇒ Object



91
92
93
94
95
96
# File 'lib/rom/registries/root.rb', line 91

def infer(id, **options)
  fetch(id) do
    inferred_config = config[handler.key].inherit(**config.component, **options)
    define_component(id: id, **inferred_config).build
  end
end

#inspectObject

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.



172
173
174
# File 'lib/rom/registries/root.rb', line 172

def inspect
  %(#<#{self.class} adapters=#{components.gateways.map(&:adapter)} keys=#{keys}>)
end

#key?(key) ⇒ Boolean

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:

  • (Boolean)


162
163
164
# File 'lib/rom/registries/root.rb', line 162

def key?(key)
  keys.include?("#{namespace}.#{key}")
end

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



149
150
151
152
153
154
# File 'lib/rom/registries/root.rb', line 149

def keys
  all = (components.keys + container.keys).uniq
  return all if path.empty?

  all.select { |key| key.start_with?(namespace) }
end

#map_with(*ids) ⇒ Object

Deprecated.


18
19
20
# File 'lib/rom/compat/registries.rb', line 18

def map_with(*ids)
  with(opts: {map_with: ids})
end

#pluginsObject

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.



144
145
146
# File 'lib/rom/registries/root.rb', line 144

def plugins
  config.component.plugins
end

#providerObject

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.



99
100
101
# File 'lib/rom/registries/root.rb', line 99

def provider
  components.provider
end

#provider_typeObject

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.



104
105
106
# File 'lib/rom/registries/root.rb', line 104

def provider_type
  config.component.type
end

#scoped(*scope, **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.



134
135
136
# File 'lib/rom/registries/root.rb', line 134

def scoped(*scope, **options)
  with(path: path + scope, **options)
end

#trigger(event, payload) ⇒ 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.



12
13
14
# File 'lib/rom/compat/registries.rb', line 12

def trigger(event, payload)
  notifications&.trigger(event, payload)
end