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

Methods included from Initializer

extended

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.



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

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

Instance Attribute Details

#cacheCache (readonly)

Returns local cache instance.

Returns:

  • (Cache)

    local cache instance



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

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

#elementsHash (readonly)

Returns Internal hash for storing registry objects.

Returns:

  • (Hash)

    Internal hash for storing registry objects



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

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.



39
40
41
42
43
44
45
# File 'lib/rom/registry.rb', line 39

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



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

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

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



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

def self.element_not_found_error = ElementNotFoundError

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



25
26
27
28
29
30
31
# File 'lib/rom/registry.rb', line 25

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.



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

def each(&)
  return to_enum unless block_given?

  elements.each(&)
end

#each_valueObject

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.



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

def each_value(&)
  return to_enum(:each_value) unless block_given?

  elements.each_value(&)
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)


80
81
82
83
84
85
86
87
88
# File 'lib/rom/registry.rb', line 80

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)


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

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

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



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

def map(&)
  new_elements = elements.transform_values(&)
  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.



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

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

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


94
95
96
# File 'lib/rom/registry.rb', line 94

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.



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

def to_hash = elements

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



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

def type = self.class.name