Module: ROM::Mapper::DSL::ClassMethods

Defined in:
core/lib/rom/mapper/dsl.rb

Overview

Class methods for all mappers

Instance Method Summary collapse

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



108
109
110
111
112
113
114
# File 'core/lib/rom/mapper/dsl.rb', line 108

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_relationObject

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



50
51
52
# File 'core/lib/rom/mapper/dsl.rb', line 50

def base_relation
  superclass.relation || relation
end

#headerObject

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



62
63
64
# File 'core/lib/rom/mapper/dsl.rb', line 62

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



24
25
26
27
28
29
30
# File 'core/lib/rom/mapper/dsl.rb', line 24

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.

Returns:

  • (Boolean)


67
68
69
# File 'core/lib/rom/mapper/dsl.rb', line 67

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

Parameters:

  • plugin (Symbol)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :adapter (Symbol) — default: :default

    first adapter to check for plugin



39
40
41
42
43
# File 'core/lib/rom/mapper/dsl.rb', line 39

def use(plugin, options = {})
  adapter = options.fetch(:adapter, :default)

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