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

Defined in:
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



96
97
98
99
100
101
102
# File 'lib/rom/mapper/dsl.rb', line 96

def method_missing(name, *args, &block)
  if attribute_dsl.respond_to?(name)
    attribute_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



38
39
40
# File 'lib/rom/mapper/dsl.rb', line 38

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



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

def header
  @header ||= attribute_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("@attribute_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)


55
56
57
# File 'lib/rom/mapper/dsl.rb', line 55

def respond_to_missing?(name, _include_private = false)
  attribute_dsl.respond_to?(name) || super
end