Class: ROM::Mapper::MapperDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/mapper/mapper_dsl.rb

Overview

Mapper definition DSL used by Setup DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, mapper_classes, block) ⇒ MapperDSL

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 a new instance of MapperDSL.



12
13
14
15
16
17
18
19
20
# File 'lib/rom/mapper/mapper_dsl.rb', line 12

def initialize(configuration, mapper_classes, block)
  @configuration = configuration
  @mapper_classes = mapper_classes
  @defined_mappers = []

  instance_exec(&block)

  @mapper_classes = @defined_mappers
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



9
10
11
# File 'lib/rom/mapper/mapper_dsl.rb', line 9

def configuration
  @configuration
end

#defined_mappersObject (readonly)

Returns the value of attribute defined_mappers.



9
10
11
# File 'lib/rom/mapper/mapper_dsl.rb', line 9

def defined_mappers
  @defined_mappers
end

#mapper_classesObject (readonly)

Returns the value of attribute mapper_classes.



9
10
11
# File 'lib/rom/mapper/mapper_dsl.rb', line 9

def mapper_classes
  @mapper_classes
end

Instance Method Details

#define(name, options = EMPTY_HASH, &block) ⇒ Class

Define a mapper class

Parameters:

  • name (Symbol)

    of the mapper

  • options (Hash) (defaults to: EMPTY_HASH)

Returns:

  • (Class)


30
31
32
33
# File 'lib/rom/mapper/mapper_dsl.rb', line 30

def define(name, options = EMPTY_HASH, &block)
  @defined_mappers << Builder.build_class(name, (@mapper_classes + @defined_mappers), options, &block)
  self
end

#register(relation, mappers) ⇒ Object

TODO



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

def register(relation, mappers)
  configuration.register_mapper(relation => mappers)
end