module ROM::Mapper::DSL::ClassMethods
Class methods for all mappers
@private
Public Instance Methods
Return base_relation
used for creating mapper registry
This is used to “gather” mappers under same root name
@api private
# File lib/rom/mapper/dsl.rb, line 49 def base_relation if superclass.relation superclass.relation else relation end end
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
@api private
# File lib/rom/mapper/dsl.rb, line 65 def header @header ||= dsl.header end
Set base ivars for the mapper class
@api private
# 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
@api private
# File lib/rom/mapper/dsl.rb, line 70 def respond_to_missing?(name, _include_private = false) dsl.respond_to?(name) || super end
include a registered plugin in this mapper
@param [Symbol] plugin @param [Hash] options @option options [Symbol] :adapter (:default) first adapter to check for plugin
@api public
# File lib/rom/mapper/dsl.rb, line 38 def use(plugin, options = {}) adapter = options.fetch(:adapter, :default) ROM.plugin_registry.mappers.fetch(plugin, adapter).apply_to(self) end
Private Instance Methods
Return default attributes that might have been inherited from the superclass
@api private
# File lib/rom/mapper/dsl.rb, line 92 def attributes @attributes ||= if superclass.respond_to?(:attributes, true) && inherit_header superclass.attributes.dup else [] end end
Create the attribute DSL
instance used by the mapper class
@api private
# File lib/rom/mapper/dsl.rb, line 104 def dsl @dsl ||= AttributeDSL.new(attributes, options) end
Delegate Attribute DSL
method to the dsl instance
@api private
# File lib/rom/mapper/dsl.rb, line 111 def method_missing(name, *args, &block) if dsl.respond_to?(name) dsl.public_send(name, *args, &block) else super end end
Return default Attribute DSL
options based on settings of the mapper class
@api private
# File lib/rom/mapper/dsl.rb, line 80 def options { copy_keys: copy_keys, prefix: prefix, prefix_separator: prefix_separator, symbolize_keys: symbolize_keys, reject_keys: reject_keys } end