Class: ROM::CommandCompiler Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::Cache, Initializer
Defined in:
lib/rom/command_compiler.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builds commands for relations.

This class is used by repositories to automatically create commands for their relations. This is used both by ‘Repository#command` method and `commands` repository class macros.

API:

  • private

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Initializer

extended

Instance Attribute Details

#adapterSymbol (readonly)

Returns The adapter identifier ie :sql or :http.

Returns:

  • The adapter identifier ie :sql or :http



47
# File 'lib/rom/command_compiler.rb', line 47

option :adapter, optional: true

#commandsROM::Registry (readonly)

Returns Command registries with custom commands.

Returns:

  • Command registries with custom commands



35
# File 'lib/rom/command_compiler.rb', line 35

param :commands

#gatewaysROM::Registry (readonly)

Returns Gateways used for command extensions.

Returns:

  • Gateways used for command extensions



27
# File 'lib/rom/command_compiler.rb', line 27

param :gateways

#idSymbol (readonly)

Returns The command type registry identifier.

Returns:

  • The command type registry identifier



43
# File 'lib/rom/command_compiler.rb', line 43

option :id, optional: true

#metaArray<Symbol> (readonly)

Returns Meta data for a command.

Returns:

  • Meta data for a command



59
# File 'lib/rom/command_compiler.rb', line 59

option :meta, optional: true

#notificationsNotifications::EventBus (readonly)

Returns Configuration notifications event bus.

Returns:

  • Configuration notifications event bus



39
# File 'lib/rom/command_compiler.rb', line 39

param :notifications

#pluginsArray<Symbol> (readonly)

Returns a list of optional plugins that will be enabled for commands.

Returns:

  • a list of optional plugins that will be enabled for commands



55
# File 'lib/rom/command_compiler.rb', line 55

option :plugins, optional: true, default: -> { EMPTY_ARRAY }

#registryHash (readonly)

Returns local registry where commands will be stored during compilation.

Returns:

  • local registry where commands will be stored during compilation



51
# File 'lib/rom/command_compiler.rb', line 51

option :registry, optional: true, default: -> { self.class.registry }

#relationsROM::RelationRegistry (readonly)

Returns Relations used with a given compiler.

Returns:

  • Relations used with a given compiler



31
# File 'lib/rom/command_compiler.rb', line 31

param :relations

Class Method Details

.registryObject

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.

API:

  • private



21
22
23
# File 'lib/rom/command_compiler.rb', line 21

def self.registry
  @__registry__ ||= Hash.new { |h, k| h[k] = {} }
end

Instance Method Details

#[](type, adapter, ast, plugins, meta) ⇒ Command, CommandProxy Also known as: []

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.

Return a specific command type for a given adapter and relation AST

This class holds its own registry where all generated commands are being stored

CommandProxy is returned for complex command graphs as they expect root relation name to be present in the input, which we don’t want to have in repositories. It might be worth looking into removing this requirement from rom core Command::Graph API.

Parameters:

  • The type of command

  • The adapter identifier

  • The AST representation of a relation

  • A list of optional command plugins that should be used

  • Meta data for a command

Returns:

API:

  • private



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rom/command_compiler.rb', line 81

def call(*args)
  fetch_or_store(args.hash) do
    type, adapter, ast, plugins, meta = args

    compiler = with(
      id: type,
      adapter: adapter,
      plugins: Array(plugins),
      meta: meta
    )

    graph_opts = compiler.visit(ast)
    command = ROM::Commands::Graph.build(registry, graph_opts)

    if command.graph?
      CommandProxy.new(command)
    elsif command.lazy?
      command.unwrap
    else
      command
    end
  end
end

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

API:

  • private



107
108
109
110
111
# File 'lib/rom/command_compiler.rb', line 107

def type
  @_type ||= Commands.const_get(Dry::Core::Inflector.classify(id))[adapter]
rescue NameError
  nil
end

#visit(ast, *args) ⇒ 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.

API:

  • private



114
115
116
117
# File 'lib/rom/command_compiler.rb', line 114

def visit(ast, *args)
  name, node = ast
  __send__(:"visit_#{name}", node, *args)
end