Class: ROM::Components::DSL::Core

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

Direct Known Subclasses

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

Class Method Summary collapse

Instance Method Summary collapse

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.



35
36
37
38
# File 'lib/rom/components/dsl/core.rb', line 35

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

Instance Method Details

#build_class(name: class_name, parent: class_parent, &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.



41
42
43
44
45
46
# File 'lib/rom/components/dsl/core.rb', line 41

def build_class(name: class_name, parent: class_parent, &block)
  Dry::Core::ClassBuilder.new(name: name, parent: parent).call do |klass|
    klass.config.component.update(config)
    klass.class_exec(self, &block) if block
  end
end

#call(**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.



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

def call(**options)
  components.add(key, config: configure, block: block, **options)
end

#configureObject

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/components/dsl/core.rb', line 64

def configure
  config.freeze
end

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



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rom/components/dsl/core.rb', line 83

def enable_plugins
  config.plugins.map! do |plugin|
    if plugin.is_a?(Symbol)
      plugins[plugin].configure.enable(self)
    elsif plugin.type == type
      plugin.configure.enable(respond_to?(:constant) ? constant : self)
    else
      plugin
    end
  end
end

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



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

def enabled_plugins
  config.plugins
    .select { |plugin| plugin.type == type }
    .to_h { |plugin| [plugin.name, plugin] }
end

#keyObject

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.



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

def key
  self.class.key
end

#plugin(name, **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.



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

def plugin(name, **options)
  plugin = enabled_plugins[name]
  plugin.config.update(options) unless options.empty?
  plugin
end

#pluginsObject Originally defined in module Plugins::ClassMethods

Return all available plugins for the component type

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



54
55
56
# File 'lib/rom/components/dsl/core.rb', line 54

def type
  self.class.type
end

#use(name, **options) ⇒ Object Originally defined in module Plugins::ClassMethods

Include a registered plugin in this relation class

Parameters:

  • plugin (Symbol)
  • options (Hash)

Options Hash (**options):

  • :adapter (Symbol) — default: :default

    first adapter to check for plugin