Class: ROM::Components::DSL::Command

Inherits:
Core
  • Object
show all
Defined in:
lib/rom/components/dsl/command.rb

Overview

Command define DSL used by Setup#commands

Instance Method Summary collapse

Instance Method Details

#adapter_namespaceObject

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/command.rb', line 54

def adapter_namespace
  ROM::Command.adapter_namespace(adapter)
end

#class_name(command_type) ⇒ 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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/rom/components/dsl/command.rb', line 42

def class_name(command_type)
  class_name_inferrer[
    config[:relation],
    type: :command,
    inflector: inflector,
    adapter: adapter,
    command_type: command_type,
    class_namespace: provider.config.class_namespace
  ]
end

#define(id, type: id, **options, &block) ⇒ Class

Define a command class

Parameters:

  • name (Symbol)

    of the command

  • options (Hash)

Options Hash (**options):

  • :type (Symbol)

    The type of the command

Returns:

  • (Class)

    generated class



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rom/components/dsl/command.rb', line 25

def define(id, type: id, **options, &block)
  command_type = inflector.classify(type)
  parent = adapter_namespace.const_get(command_type)

  constant = build_class(name: class_name(command_type), parent: parent) do |dsl|
    config.update(options)

    config.component.update(dsl.config)
    config.component.update(id: id, adapter: dsl.adapter)

    class_exec(&block) if block
  end

  call(constant: constant, config: constant.config.component)
end