module ROM::Mapper::DSL::ClassMethods

Class methods for all mappers

@private

Public Instance Methods

base_relation() click to toggle source

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 51
def base_relation
  superclass.relation || relation
end
header() click to toggle source

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 63
def header
  @header ||= dsl.header
end
inherited(klass) click to toggle source

Set base ivars for the mapper class

@api private

Calls superclass method
# 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) click to toggle source

@api private

Calls superclass method
# 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 = {}) click to toggle source

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 40
def use(plugin, options = {})
  adapter = options.fetch(:adapter, :default)

  ROM.plugin_registry[:mapper].fetch(plugin, adapter).apply_to(self)
end

Private Instance Methods

attributes() click to toggle source

Return default attributes that might have been inherited from the superclass

@api private

# File lib/rom/mapper/dsl.rb, line 90
def attributes
  @attributes ||=
    if superclass.respond_to?(:attributes, true) && inherit_header
      superclass.attributes.dup
    else
      []
    end
end
dsl() click to toggle source

Create the attribute DSL instance used by the mapper class

@api private

# File lib/rom/mapper/dsl.rb, line 102
def dsl
  @dsl ||= AttributeDSL.new(attributes, options)
end
method_missing(name, *args, &block) click to toggle source

Delegate Attribute DSL method to the dsl instance

@api private

Calls superclass method
# 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
options() click to toggle source

Return default Attribute DSL options based on settings of the mapper class

@api private

# File lib/rom/mapper/dsl.rb, line 78
def options
  { copy_keys: copy_keys,
    prefix: prefix,
    prefix_separator: prefix_separator,
    symbolize_keys: symbolize_keys,
    reject_keys: reject_keys }
end