Class: ROM::Repository::CommandCompiler Private
- Inherits:
-
Object
- Object
- ROM::Repository::CommandCompiler
- Extended by:
- Dry::Core::Cache
- Defined in:
- lib/rom/repository/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 ⇒ Object readonly private
- #container ⇒ Object readonly private
- #id ⇒ Object readonly private
- #options ⇒ Object readonly private
- #plugins ⇒ Object readonly private
- #registry ⇒ Object readonly private
Class Method Summary collapse
-
.[](container, type, adapter, ast, plugins, options) ⇒ Command, CommandProxy
private
Return a specific command type for a given adapter and relation AST.
- .registry ⇒ Object private
Instance Method Summary collapse
-
#initialize(id, adapter, container, registry, plugins, options) ⇒ CommandCompiler
constructor
private
A new instance of CommandCompiler.
- #type ⇒ Object private
- #visit(ast, *args) ⇒ Object private
Constructor Details
#initialize(id, adapter, container, registry, plugins, options) ⇒ CommandCompiler
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.
Returns a new instance of CommandCompiler.
88 89 90 91 92 93 94 95 |
# File 'lib/rom/repository/command_compiler.rb', line 88 def initialize(id, adapter, container, registry, plugins, ) @id = id @adapter = adapter @registry = registry @container = container @plugins = Array(plugins) @options = end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
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.
69 70 71 |
# File 'lib/rom/repository/command_compiler.rb', line 69 def adapter @adapter end |
#container ⇒ Object (readonly)
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.
73 74 75 |
# File 'lib/rom/repository/command_compiler.rb', line 73 def container @container end |
#id ⇒ Object (readonly)
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.
65 66 67 |
# File 'lib/rom/repository/command_compiler.rb', line 65 def id @id end |
#options ⇒ Object (readonly)
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.
85 86 87 |
# File 'lib/rom/repository/command_compiler.rb', line 85 def @options end |
#plugins ⇒ Object (readonly)
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.
81 82 83 |
# File 'lib/rom/repository/command_compiler.rb', line 81 def plugins @plugins end |
#registry ⇒ Object (readonly)
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.
77 78 79 |
# File 'lib/rom/repository/command_compiler.rb', line 77 def registry @registry end |
Class Method Details
.[](container, type, adapter, ast, plugins, options) ⇒ Command, CommandProxy
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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rom/repository/command_compiler.rb', line 40 def self.[](*args) fetch_or_store(args.hash) do container, type, adapter, ast, plugins, = args graph_opts = new(type, adapter, container, registry, plugins, ).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 |
.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.
59 60 61 |
# File 'lib/rom/repository/command_compiler.rb', line 59 def self.registry @__registry__ ||= Hash.new { |h, k| h[k] = {} } end |
Instance Method Details
#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.
98 99 100 101 102 |
# File 'lib/rom/repository/command_compiler.rb', line 98 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.
105 106 107 108 |
# File 'lib/rom/repository/command_compiler.rb', line 105 def visit(ast, *args) name, node = ast __send__(:"visit_#{name}", node, *args) end |