Class: ROM::CommandRegistry
- Defined in:
- lib/rom/command_registry.rb
Overview
Specialized registry class for commands
Instance Attribute Summary collapse
-
#compiler ⇒ CommandCompiler
readonly
A command compiler instance.
-
#mapper ⇒ Object#call
readonly
Default mapper for processing command results.
-
#mappers ⇒ MapperRegistry
readonly
Optional mapper registry.
-
#relation_name ⇒ Relation::Name
readonly
The name of a relation.
Attributes inherited from Registry
Class Method Summary collapse
Instance Method Summary collapse
-
#[](*args) ⇒ Command, Command::Composite
Return a command from the registry.
-
#elements ⇒ Registry
private
Internal command registry.
-
#map_with(mapper_name) ⇒ CommandRegistry
Specify a mapper that should be used for commands from this registry.
- #set_compiler(compiler) ⇒ Object private
- #set_mappers(mappers) ⇒ Object private
Methods inherited from Registry
[], build, #each, #each_value, #fetch, #key?, #map, #merge, new, #to_hash, #type
Methods included from Initializer
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
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.
Allow retrieving commands using dot-notation
111 112 113 114 115 116 117 |
# File 'lib/rom/command_registry.rb', line 111 def method_missing(name, *) if key?(name) self[name] else super end end |
Instance Attribute Details
#compiler ⇒ CommandCompiler (readonly)
Returns A command compiler instance.
34 |
# File 'lib/rom/command_registry.rb', line 34 option :compiler, optional: true |
#mapper ⇒ Object#call (readonly)
Returns Default mapper for processing command results.
30 |
# File 'lib/rom/command_registry.rb', line 30 option :mapper, optional: true |
#mappers ⇒ MapperRegistry (readonly)
Returns Optional mapper registry.
26 |
# File 'lib/rom/command_registry.rb', line 26 option :mappers, optional: true |
#relation_name ⇒ Relation::Name (readonly)
Returns The name of a relation.
22 |
# File 'lib/rom/command_registry.rb', line 22 option :relation_name |
Class Method Details
.element_not_found_error ⇒ 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.
37 |
# File 'lib/rom/command_registry.rb', line 37 def self.element_not_found_error = CommandNotFoundError |
Instance Method Details
#[](name) ⇒ Command, Command::Composite #[](*args) ⇒ Command, Command::Composite
Return a command from the registry
If mapper is set command will be turned into a composite command with auto-mapping
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rom/command_registry.rb', line 61 def [](*args) if args.size.equal?(1) command = super mapper = [:mapper] if mapper command.curry >> mapper else command end else cache.fetch_or_store(args.hash) { compiler.(*args) } end end |
#elements ⇒ Registry
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.
Internal command registry
18 |
# File 'lib/rom/command_registry.rb', line 18 param :elements |
#map_with(mapper_name) ⇒ CommandRegistry
Specify a mapper that should be used for commands from this registry
87 |
# File 'lib/rom/command_registry.rb', line 87 def map_with(mapper_name) = with(mapper: mappers[mapper_name]) |
#set_compiler(compiler) ⇒ 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.
90 91 92 |
# File 'lib/rom/command_registry.rb', line 90 def set_compiler(compiler) # rubocop:disable Naming/AccessorMethodName [:compiler] = @compiler = compiler end |
#set_mappers(mappers) ⇒ 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.
95 96 97 |
# File 'lib/rom/command_registry.rb', line 95 def set_mappers(mappers) # rubocop:disable Naming/AccessorMethodName [:mappers] = @mappers = mappers end |