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
-
#cache ⇒ Cache
readonly
Local cache instance.
-
#command_class ⇒ Symbol
readonly
The command command_class.
-
#id ⇒ Symbol
readonly
The command registry identifier.
-
#meta ⇒ Array<Symbol>
readonly
Meta data for a command.
-
#plugins ⇒ Array<Symbol>
readonly
A list of optional plugins that will be enabled for commands.
- #registry ⇒ Registry::Root readonly
Instance Method Summary collapse
-
#[](id, adapter, ast, plugins, meta) ⇒ Command, CommandProxy
(also: #[])
private
Return a specific command command_class for a given adapter and relation AST.
- #relations ⇒ Object private
- #visit(ast, *args) ⇒ Object private
Instance Attribute Details
#cache ⇒ Cache (readonly)
Returns local cache instance.
41 |
# File 'lib/rom/command_compiler.rb', line 41 option :cache, default: -> { Cache.new } |
#command_class ⇒ Symbol (readonly)
Returns The command command_class.
25 |
# File 'lib/rom/command_compiler.rb', line 25 option :command_class, optional: true |
#id ⇒ Symbol (readonly)
Returns The command registry identifier.
21 |
# File 'lib/rom/command_compiler.rb', line 21 option :id, optional: true |
#meta ⇒ Array<Symbol> (readonly)
Returns Meta data for a command.
37 |
# File 'lib/rom/command_compiler.rb', line 37 option :meta, optional: true |
#plugins ⇒ Array<Symbol> (readonly)
Returns a list of optional plugins that will be enabled for commands.
33 |
# File 'lib/rom/command_compiler.rb', line 33 option :plugins, optional: true, default: -> { EMPTY_HASH } |
#registry ⇒ Registry::Root (readonly)
29 |
# File 'lib/rom/command_compiler.rb', line 29 option :registry, default: -> { Registry::Root.new } |
Instance Method Details
#[](id, 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 command_class 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rom/command_compiler.rb', line 63 def call(*args) cache.fetch_or_store(args.hash) do id, adapter, ast, plugins, , = args component = registry.components.get(:commands, id: id) command_class = if component component.constant else Command.adapter_namespace(adapter).const_get(Inflector.classify(id)) end plugins_with_opts = Array(plugins) .map { |plugin| [plugin, .fetch(plugin) { EMPTY_HASH }] } .to_h compiler = with( id: id, command_class: command_class, adapter: adapter, plugins: plugins_with_opts, meta: ) graph_opts = compiler.visit(ast) command = ROM::Commands::Graph.build(registry.root.commands, graph_opts) if command.graph? root = Inflector.singularize(command.name.relation).to_sym CommandProxy.new(command, root) elsif command.lazy? command.unwrap else command end end end |
#relations ⇒ 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.
110 111 112 |
# File 'lib/rom/command_compiler.rb', line 110 def relations registry.root.relations 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.
104 105 106 107 |
# File 'lib/rom/command_compiler.rb', line 104 def visit(ast, *args) name, node = ast __send__(:"visit_#{name}", node, *args) end |