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
109 110 111 112 113 114 115 |
# File 'lib/rom/mapper/dsl.rb', line 109 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 |
# File 'lib/rom/mapper/dsl.rb', line 51 def base_relation superclass.relation || relation 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
63 64 65 |
# File 'lib/rom/mapper/dsl.rb', line 63 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.
68 69 70 |
# File 'lib/rom/mapper/dsl.rb', line 68 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[:mapper].fetch(plugin, adapter).apply_to(self) end |