Module: ROM::Mapper::DSL::ClassMethods
- Defined in:
- lib/rom/mapper/dsl.rb
Overview
Class methods for all mappers
Instance Method Summary collapse
-
#base_relation ⇒ Object
private
Return base_relation used for creating mapper registry.
-
#header ⇒ Object
private
Return header of the mapper.
-
#inherited(klass) ⇒ Object
private
Set base ivars for the mapper class.
- #respond_to_missing?(name, _include_private = false) ⇒ Boolean private
-
#use(plugin, options = {}) ⇒ Object
include a registered plugin in this mapper.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
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.
Delegate Attribute DSL method to the dsl instance
113 114 115 116 117 118 119 |
# File 'lib/rom/mapper/dsl.rb', line 113 def method_missing(name, *args, &block) if dsl.respond_to?(name) dsl.public_send(name, *args, &block) else super end end |
Instance Method Details
#base_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.
Return base_relation used for creating mapper registry
This is used to “gather” mappers under same root name
51 52 53 54 55 56 57 |
# File 'lib/rom/mapper/dsl.rb', line 51 def base_relation if superclass.relation superclass.relation else relation end end |
#header ⇒ 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.
Return header of the mapper
This is memoized so mutating mapper class won’t have an effect wrt header after it was initialized for the first time.
TODO: freezing mapper class here is probably a good idea
67 68 69 |
# File 'lib/rom/mapper/dsl.rb', line 67 def header @header ||= dsl.header end |
#inherited(klass) ⇒ 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.
Set base ivars for the mapper class
25 26 27 28 29 30 31 |
# File 'lib/rom/mapper/dsl.rb', line 25 def inherited(klass) super klass.instance_variable_set('@attributes', nil) klass.instance_variable_set('@header', nil) klass.instance_variable_set('@dsl', nil) end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
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.
72 73 74 |
# File 'lib/rom/mapper/dsl.rb', line 72 def respond_to_missing?(name, _include_private = false) dsl.respond_to?(name) || super end |
#use(plugin, options = {}) ⇒ Object
include a registered plugin in this mapper
40 41 42 43 44 |
# File 'lib/rom/mapper/dsl.rb', line 40 def use(plugin, = {}) adapter = .fetch(:adapter, :default) ROM.plugin_registry.mappers.fetch(plugin, adapter).apply_to(self) end |