Class: ROM::ConfigurationDSL::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/configuration_dsl/command.rb

Overview

Setup DSL-specific command extensions

Class Method Summary collapse

Class Method Details

.build_class(name, relation, options = EMPTY_HASH, &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.

Generate a command subclass

This is used by Setup#commands DSL and its ‘define` block



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rom/configuration_dsl/command.rb', line 15

def self.build_class(name, relation, options = EMPTY_HASH, &block)
  type = options.fetch(:type) { name }
  command_type = Inflector.classify(type)
  adapter = options.fetch(:adapter)
  parent = ROM::Command.adapter_namespace(adapter).const_get(command_type)
  class_name = generate_class_name(adapter, command_type, relation)

  Dry::Core::ClassBuilder.new(name: class_name, parent: parent).call do |klass|
    klass.register_as(name)
    klass.relation(relation)
    klass.class_eval(&block) if block
  end
end

.generate_class_name(adapter, command_type, relation) ⇒ 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 command subclass name based on adapter, type and relation



32
33
34
35
36
37
38
# File 'lib/rom/configuration_dsl/command.rb', line 32

def self.generate_class_name(adapter, command_type, relation)
  pieces = ['ROM']
  pieces << Inflector.classify(adapter)
  pieces << 'Commands'
  pieces << "#{command_type}[#{Inflector.classify(relation)}s]"
  pieces.join('::')
end