Module: ROM::Command::ClassInterface
- Included in:
- ROM::Command
- Defined in:
- core/lib/rom/commands/class_interface.rb
Instance Method Summary collapse
-
#[](adapter) ⇒ Class
Return adapter specific sub-class based on the adapter identifier.
-
#after(*hooks) ⇒ Array<Hash, Symbol>
Set after-execute hooks.
-
#before(*hooks) ⇒ Array<Hash, Symbol>
Set before-execute hooks.
-
#build(relation, **options) ⇒ Command
Build a command class for a specific relation with options.
-
#create_class(name, type) {|Class| ... } ⇒ Class, Object
Create a command class with a specific type.
-
#extend_for_relation(relation) ⇒ Class
Extend a command class with relation view methods.
-
#use(plugin, **options) ⇒ Object
Use a configured plugin in this relation.
Instance Method Details
#[](adapter) ⇒ Class
Return adapter specific sub-class based on the adapter identifier
This is a syntax sugar to make things consistent
43 44 45 |
# File 'core/lib/rom/commands/class_interface.rb', line 43 def [](adapter) adapter_namespace(adapter).const_get(Inflector.demodulize(name)) end |
#after(hook) ⇒ Array<Hash, Symbol> #after(hook_opts) ⇒ Array<Hash, Symbol>
Set after-execute hooks
211 212 213 214 215 216 217 |
# File 'core/lib/rom/commands/class_interface.rb', line 211 def after(*hooks) if !hooks.empty? set_hooks(:after, hooks) else @after end end |
#before(hook) ⇒ Array<Hash, Symbol> #before(hook_opts) ⇒ Array<Hash, Symbol>
Set before-execute hooks
166 167 168 169 170 171 172 |
# File 'core/lib/rom/commands/class_interface.rb', line 166 def before(*hooks) if !hooks.empty? set_hooks(:before, hooks) else @before end end |
#build(relation, **options) ⇒ Command
Build a command class for a specific relation with options
74 75 76 |
# File 'core/lib/rom/commands/class_interface.rb', line 74 def build(relation, **) new(relation, **self., **) end |
#create_class(name, type) {|Class| ... } ⇒ Class, Object
Create a command class with a specific type
88 89 90 91 92 93 94 95 96 97 98 |
# File 'core/lib/rom/commands/class_interface.rb', line 88 def create_class(name, type, &block) klass = Dry::Core::ClassBuilder .new(name: "#{Inflector.classify(type)}[:#{name}]", parent: type) .call if block yield(klass) else klass end end |
#extend_for_relation(relation) ⇒ Class
Extend a command class with relation view methods
125 126 127 |
# File 'core/lib/rom/commands/class_interface.rb', line 125 def extend_for_relation(relation) include(relation_methods_mod(relation.class)) end |
#use(plugin, **options) ⇒ Object
Use a configured plugin in this relation
114 115 116 |
# File 'core/lib/rom/commands/class_interface.rb', line 114 def use(plugin, **) ROM.plugin_registry[:command].fetch(plugin, adapter).apply_to(self, **) end |