class ROM::CommandRegistry
Specialized registry class for commands
@api public
Public Class Methods
element_not_found_error()
click to toggle source
@api private
# File lib/rom/command_registry.rb, line 37 def self.element_not_found_error CommandNotFoundError end
Public Instance Methods
[](*args)
click to toggle source
Return a command from the registry
If mapper is set command will be turned into a composite command with auto-mapping
@overload [](name)
@param [Symbol] name The command identifier from the registry @example create_user = rom.commands[:users][:create] create_user[name: 'Jane'] # with mapping, assuming :entity mapper is registered for :users relation create_user = rom.commands[:users].map_with(:entity)[:create] create_user[name: 'Jane'] # => result is sent through :entity mapper
@overload [](*args)
@param [Array] *args {CommandCompiler} arguments @see CommandCompiler#call
@return [Command,Command::Composite]
@api public
Calls superclass method
# File lib/rom/command_registry.rb, line 63 def [](*args) if args.size.equal?(1) command = super mapper = options[:mapper] if mapper command.curry >> mapper else command end else cache.fetch_or_store(args.hash) { compiler.(*args) } end end
map_with(mapper_name)
click to toggle source
Specify a mapper that should be used for commands from this registry
@example
entity_commands = rom.commands[:users].map_with(:entity)
@param [Symbol] mapper_name The name of a registered mapper
@return [CommandRegistry]
@api public
# File lib/rom/command_registry.rb, line 89 def map_with(mapper_name) with(mapper: mappers[mapper_name]) end
set_compiler(compiler)
click to toggle source
@api private
# File lib/rom/command_registry.rb, line 94 def set_compiler(compiler) options[:compiler] = @compiler = compiler end
set_mappers(mappers)
click to toggle source
@api private
# File lib/rom/command_registry.rb, line 99 def set_mappers(mappers) options[:mappers] = @mappers = mappers end
Private Instance Methods
method_missing(name, *)
click to toggle source
Allow retrieving commands using dot-notation
@api private
Calls superclass method
# File lib/rom/command_registry.rb, line 115 def method_missing(name, *) if key?(name) self[name] else super end end
respond_to_missing?(name, include_private = false)
click to toggle source
Allow checking if a certain command is available using dot-notation
@api private
Calls superclass method
# File lib/rom/command_registry.rb, line 108 def respond_to_missing?(name, include_private = false) key?(name) || super end