Class: ROM::Components::DSL::Mapper
- Defined in:
- lib/rom/components/dsl/mapper.rb
Overview
Mapper definition DSL used by Setup DSL
Instance Method Summary collapse
- #class_name(id) ⇒ Object private
- #class_parent(parent) ⇒ Object private
-
#define(id, parent: id, **options, &block) ⇒ Class
Define a mapper class.
-
#register(namespace, mappers) ⇒ Array<Components::Mapper>
Register any object as a mapper for a given relation.
Instance Method Details
#class_name(id) ⇒ 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.
47 48 49 |
# File 'lib/rom/components/dsl/mapper.rb', line 47 def class_name(id) "ROM::Mapper[#{id}]" end |
#class_parent(parent) ⇒ 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.
42 43 44 |
# File 'lib/rom/components/dsl/mapper.rb', line 42 def class_parent(parent) components.get(:mappers, relation: parent)&.constant || ROM::Mapper end |
#define(id, parent: id, **options, &block) ⇒ Class
Define a mapper class
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rom/components/dsl/mapper.rb', line 26 def define(id, parent: id, **, &block) class_opts = {name: class_name(id), parent: class_parent(parent)} constant = build_class(**class_opts) do |dsl| config.update() config.component.update(id: id, relation: parent) config.component.join!({namespace: parent}, :right) if dsl.config.namespace != parent class_eval(&block) if block end call(constant: constant, config: constant.config.component) end |
#register(namespace, mappers) ⇒ Array<Components::Mapper>
Register any object as a mapper for a given relation
59 60 61 62 63 64 65 66 |
# File 'lib/rom/components/dsl/mapper.rb', line 59 def register(namespace, mappers) mappers.map do |id, mapper| call( object: mapper, config: config.join({id: id, relation: namespace, namespace: namespace}, :right) ) end end |