Class: ROM::Registry Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::Cache, Initializer
Includes:
Enumerable
Defined in:
lib/rom/registry.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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)

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.


112
113
114
# File 'lib/rom/registry.rb', line 112

def method_missing(name, *)
  elements.fetch(name) { super }
end

Instance Attribute Details

#cacheCache (readonly)

Returns local cache instance.

Returns:

  • (Cache)

    local cache instance


26
# File 'lib/rom/registry.rb', line 26

option :cache, default: -> { Cache.new }

#elementsHash (readonly)

Returns Internal hash for storing registry objects.

Returns:

  • (Hash)

    Internal hash for storing registry objects


22
# File 'lib/rom/registry.rb', line 22

param :elements

Class Method Details

.[](identifier) ⇒ 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.


45
46
47
48
49
50
51
# File 'lib/rom/registry.rb', line 45

def self.[](identifier)
  fetch_or_store(identifier) do
    ::Dry::Core::ClassBuilder
      .new(parent: self, name: "#{name}[:#{identifier}]")
      .call
  end
end

.build(elements = {}) ⇒ 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.

Create a registry without options


40
41
42
# File 'lib/rom/registry.rb', line 40

def self.build(elements = {})
  new(elements, **{})
end

.element_not_found_errorObject

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.


54
55
56
# File 'lib/rom/registry.rb', line 54

def self.element_not_found_error
  ElementNotFoundError
end

.new(*args, **kwargs) ⇒ 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.


29
30
31
32
33
34
35
# File 'lib/rom/registry.rb', line 29

def self.new(*args, **kwargs)
  if args.empty? && kwargs.empty?
    super({}, **{})
  else
    super
  end
end

Instance Method Details

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


77
78
79
80
81
# File 'lib/rom/registry.rb', line 77

def each
  return to_enum unless block_given?

  elements.each { |element| yield(element) }
end

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

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.

Raises:

  • (ArgumentError)

89
90
91
92
93
94
95
96
97
# File 'lib/rom/registry.rb', line 89

def fetch(key)
  raise ArgumentError, "key cannot be nil" if key.nil?

  elements.fetch(key.to_sym) do
    return yield if block_given?

    raise self.class.element_not_found_error.new(key, self)
  end
end

#key?(name) ⇒ 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)

84
85
86
# File 'lib/rom/registry.rb', line 84

def key?(name)
  !name.nil? && elements.key?(name.to_sym)
end

#mapObject

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.


69
70
71
72
73
74
# File 'lib/rom/registry.rb', line 69

def map
  new_elements = elements.each_with_object({}) do |(name, element), h|
    h[name] = yield(element)
  end
  self.class.new(new_elements, **options)
end

#merge(other) ⇒ 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.


59
60
61
# File 'lib/rom/registry.rb', line 59

def merge(other)
  self.class.new(Hash(other), **options)
end

#respond_to_missing?(name, include_private = false) ⇒ 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)

105
106
107
# File 'lib/rom/registry.rb', line 105

def respond_to_missing?(name, include_private = false)
  elements.key?(name) || super
end

#to_hashObject

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.


64
65
66
# File 'lib/rom/registry.rb', line 64

def to_hash
  elements
end

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


100
101
102
# File 'lib/rom/registry.rb', line 100

def type
  self.class.name
end