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
110 111 112 113 114 115 116 |
# File 'lib/rom/mapper/dsl.rb', line 110 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
49 50 51 52 53 54 55 |
# File 'lib/rom/mapper/dsl.rb', line 49 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
65 66 67 |
# File 'lib/rom/mapper/dsl.rb', line 65 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
23 24 25 26 27 28 29 |
# File 'lib/rom/mapper/dsl.rb', line 23 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.
70 71 72 |
# File 'lib/rom/mapper/dsl.rb', line 70 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
38 39 40 41 42 |
# File 'lib/rom/mapper/dsl.rb', line 38 def use(plugin, = {}) adapter = .fetch(:adapter, :default) ROM.plugin_registry.mappers.fetch(plugin, adapter).apply_to(self) end |