Class: ROM::ConfigurationDSL::Command
- Inherits:
-
Object
- Object
- ROM::ConfigurationDSL::Command
- Defined in:
- core/lib/rom/configuration_dsl/command.rb
Overview
Setup DSL-specific command extensions
Class Method Summary collapse
-
.build_class(name, relation, options = EMPTY_HASH, &block) ⇒ Object
private
Generate a command subclass.
-
.generate_class_name(adapter, command_type, relation) ⇒ Object
private
Create a command subclass name based on adapter, type and relation.
Class Method Details
.build_class(name, relation, options = EMPTY_HASH, &block) ⇒ 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.
Generate a command subclass
This is used by Setup#commands DSL and its define
block
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'core/lib/rom/configuration_dsl/command.rb', line 16 def self.build_class(name, relation, = EMPTY_HASH, &block) type = .fetch(:type) { name } command_type = Inflector.classify(type) adapter = .fetch(:adapter) parent = ROM::Command.adapter_namespace(adapter).const_get(command_type) class_name = generate_class_name(adapter, command_type, relation) Dry::Core::ClassBuilder.new(name: class_name, parent: parent).call do |klass| klass.register_as(name) klass.relation(relation) klass.class_eval(&block) if block end end |
.generate_class_name(adapter, command_type, relation) ⇒ 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.
Create a command subclass name based on adapter, type and relation
33 34 35 36 37 38 39 |
# File 'core/lib/rom/configuration_dsl/command.rb', line 33 def self.generate_class_name(adapter, command_type, relation) pieces = ['ROM'] pieces << Inflector.classify(adapter) pieces << 'Commands' pieces << "#{command_type}[#{Inflector.classify(relation)}s]" pieces.join('::') end |