Module: ROM::Relation::Commands
- Included in:
- ROM::Relation, Combined
- Defined in:
- lib/rom/relation/commands.rb
Overview
Extensions for relation classes which provide access to commands
Instance Method Summary collapse
-
#command(type, mapper: nil, use: EMPTY_ARRAY, plugins_options: EMPTY_HASH, **opts) ⇒ ROM::Command
Return a command for the relation.
Instance Method Details
#command(type, mapper: nil, use: EMPTY_ARRAY, plugins_options: EMPTY_HASH, **opts) ⇒ ROM::Command
Return a command for the relation
This method can either return an existing custom command identified by ‘type` param, or generate a command dynamically based on relation AST.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rom/relation/commands.rb', line 38 def command(type, mapper: nil, use: EMPTY_ARRAY, plugins_options: EMPTY_HASH, **opts) base_command = commands.key?(type) ? commands[type] : commands[type, adapter, to_ast, use, , opts] command = if mapper base_command >> mappers[mapper] elsif mappers.any? && !base_command.is_a?(CommandProxy) mappers.reduce(base_command) { |a, (_, e)| a >> e } elsif auto_struct? || auto_map? base_command >> self.mapper else base_command end if command.restrictible? command.new(self) else command end end |