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


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

def self.build_class(name, relation, options = EMPTY_HASH, &block)
  type = options.fetch(:type) { name }
  inflector = options.fetch(:inflector) { Inflector }
  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, inflector)

  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, inflector) ⇒ 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


35
36
37
38
39
40
41
# File 'lib/rom/configuration_dsl/command.rb', line 35

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