Class: ROM::CommandCompiler Private
- Inherits:
-
Object
- Object
- ROM::CommandCompiler
- Extended by:
- 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.
Instance Attribute Summary collapse
-
#adapter ⇒ Symbol
readonly
The adapter identifier ie :sql or :http.
-
#cache ⇒ Cache
readonly
Local cache instance.
-
#commands ⇒ ROM::Registry
readonly
Command registries with custom commands.
-
#gateways ⇒ ROM::Registry
readonly
Gateways used for command extensions.
-
#id ⇒ Symbol
readonly
The command type registry identifier.
-
#meta ⇒ Array<Symbol>
readonly
Meta data for a command.
-
#notifications ⇒ Notifications::EventBus
readonly
Configuration notifications event bus.
-
#plugins ⇒ Array<Symbol>
readonly
A list of optional plugins that will be enabled for commands.
-
#plugins_options ⇒ Hash
readonly
A hash of options for the plugins.
-
#registry ⇒ Hash
readonly
Local registry where commands will be stored during compilation.
-
#relations ⇒ ROM::RelationRegistry
readonly
Relations used with a given compiler.
Class Method Summary collapse
- .registry ⇒ Object private
Instance Method Summary collapse
-
#[](type, adapter, ast, plugins, meta) ⇒ Command, CommandProxy
(also: #[])
private
Return a specific command type for a given adapter and relation AST.
- #type ⇒ Object private
- #visit(ast, *args) ⇒ Object private
Methods included from Initializer
Instance Attribute Details
#adapter ⇒ Symbol (readonly)
Returns The adapter identifier ie :sql or :http.
45 |
# File 'lib/rom/command_compiler.rb', line 45 option :adapter, optional: true |
#cache ⇒ Cache (readonly)
Returns local cache instance.
65 |
# File 'lib/rom/command_compiler.rb', line 65 option :cache, default: -> { Cache.new } |
#commands ⇒ ROM::Registry (readonly)
Returns Command registries with custom commands.
33 |
# File 'lib/rom/command_compiler.rb', line 33 param :commands |
#gateways ⇒ ROM::Registry (readonly)
Returns Gateways used for command extensions.
25 |
# File 'lib/rom/command_compiler.rb', line 25 param :gateways |
#id ⇒ Symbol (readonly)
Returns The command type registry identifier.
41 |
# File 'lib/rom/command_compiler.rb', line 41 option :id, optional: true |
#meta ⇒ Array<Symbol> (readonly)
Returns Meta data for a command.
61 |
# File 'lib/rom/command_compiler.rb', line 61 option :meta, optional: true |
#notifications ⇒ Notifications::EventBus (readonly)
Returns Configuration notifications event bus.
37 |
# File 'lib/rom/command_compiler.rb', line 37 param :notifications |
#plugins ⇒ Array<Symbol> (readonly)
Returns a list of optional plugins that will be enabled for commands.
53 |
# File 'lib/rom/command_compiler.rb', line 53 option :plugins, optional: true, default: -> { EMPTY_ARRAY } |
#plugins_options ⇒ Hash (readonly)
Returns a hash of options for the plugins.
57 |
# File 'lib/rom/command_compiler.rb', line 57 option :plugins_options, optional: true, default: -> { EMPTY_HASH } |
#registry ⇒ Hash (readonly)
Returns local registry where commands will be stored during compilation.
49 |
# File 'lib/rom/command_compiler.rb', line 49 option :registry, optional: true, default: -> { self.class.registry } |
#relations ⇒ ROM::RelationRegistry (readonly)
Returns Relations used with a given compiler.
29 |
# File 'lib/rom/command_compiler.rb', line 29 param :relations |
Class Method Details
.registry ⇒ 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.
19 20 21 |
# File 'lib/rom/command_compiler.rb', line 19 def self.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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rom/command_compiler.rb', line 87 def call(*args) cache.fetch_or_store(args.hash) do type, adapter, ast, plugins, , = args compiler = with( id: type, adapter: adapter, plugins: Array(plugins), plugins_options: , 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 |
#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.
114 115 116 117 118 |
# File 'lib/rom/command_compiler.rb', line 114 def type @_type ||= Commands.const_get(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.
121 122 123 124 |
# File 'lib/rom/command_compiler.rb', line 121 def visit(ast, *args) name, node = ast __send__(:"visit_#{name}", node, *args) end |