Class: ROM::Components::Core

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes, Initializer
Includes:
Dry::Core::Memoizable
Defined in:
lib/rom/components/core.rb,
lib/rom/compat/components.rb

Overview

Abstract component class

Direct Known Subclasses

Association, Command, Dataset, Gateway, Mapper, Relation, Schema, View

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns Component's config.

Returns:

  • (Object)

    Component's config



38
# File 'lib/rom/components/core.rb', line 38

option :config, type: Types.Instance(ROM::Configurable::Config)

#gatewayObject (readonly)



42
# File 'lib/rom/components/core.rb', line 42

option :block, type: Types.Interface(:to_proc), optional: true

#providerObject (readonly)

Returns Component's provider.

Returns:

  • (Object)

    Component's provider



34
# File 'lib/rom/components/core.rb', line 34

option :provider

Class Method Details

.inherited(klass) ⇒ 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.



27
28
29
30
# File 'lib/rom/components/core.rb', line 27

def self.inherited(klass)
  super
  klass.type(Inflector.component_id(klass).to_sym)
end

Instance Method Details

#abstractObject Also known as: abstract?



50
51
52
# File 'lib/rom/components/core.rb', line 50

def abstract
  config.abstract
end

#apply_external_plugins(plugins, already_applied) ⇒ 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.



109
110
111
112
113
114
115
# File 'lib/rom/components/core.rb', line 109

def apply_external_plugins(plugins, already_applied)
  plugins
    .reject { |plugin| already_applied.include?(plugin.name) }
    .each { |external_plugin|
      config.plugins << external_plugin.configure.enable(constant).apply
    }
end

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



97
98
99
100
101
102
103
104
105
106
# File 'lib/rom/components/core.rb', line 97

def apply_plugins
  already_applied = plugins.reject(&:applied?).map do |plugin|
    plugin.enable(constant) unless plugin.enabled?
    plugin.apply unless plugin.applied?
    plugin.name
  end

  apply_external_plugins(gateway_plugins, already_applied) if gateway?
  apply_external_plugins(provider_plugins, already_applied)
end

#buildObject

This method is meant to return a run-time component instance

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/rom/components/core.rb', line 77

def build(**)
  raise NotImplementedError
end

#componentsObject

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.



87
88
89
# File 'lib/rom/components/core.rb', line 87

def components
  provider.components
end

#gateway?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/rom/components/core.rb', line 138

def gateway?
  registry.gateways.key?(config[:gateway])
end

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



123
124
125
# File 'lib/rom/components/core.rb', line 123

def gateway_plugins
  gateway.config.plugins.select { |plugin| plugin.type == type }
end

#idObject



65
66
67
# File 'lib/rom/components/core.rb', line 65

def id
  config.id
end

#inflectorObject



82
83
84
# File 'lib/rom/components/core.rb', line 82

def inflector
  config.inflector
end

#keyString

Default container key

Returns:

  • (String)


60
61
62
# File 'lib/rom/components/core.rb', line 60

memoize def key
  "#{namespace}.#{id}"
end

#local_componentsObject

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.



92
93
94
# File 'lib/rom/components/core.rb', line 92

def local_components
  EMPTY_ARRAY
end

#namespaceObject



70
71
72
# File 'lib/rom/components/core.rb', line 70

def namespace
  config.namespace
end

#notificationsObject

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.



16
17
18
# File 'lib/rom/compat/components.rb', line 16

def notifications
  registry.notifications
end

#plugin_optionsObject



133
134
135
# File 'lib/rom/components/core.rb', line 133

def plugin_options
  plugins.map(&:plugin_options).reduce(:merge) || EMPTY_HASH
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.



118
119
120
# File 'lib/rom/components/core.rb', line 118

def plugins
  config.plugins.select { |plugin| plugin.type == type }
end

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



128
129
130
# File 'lib/rom/components/core.rb', line 128

def provider_plugins
  provider.config.component.plugins.select { |plugin| plugin.type == type }
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.



11
12
13
# File 'lib/rom/compat/components.rb', line 11

def trigger(event, payload)
  registry.trigger("configuration.#{event}", payload)
end

#typeObject



45
46
47
# File 'lib/rom/components/core.rb', line 45

def type
  self.class.type
end