Class: ROM::Mapping

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/rom/mapping.rb,
lib/rom/mapping/definition.rb

Overview

Builder DSL for ROM relations

Defined Under Namespace

Classes: Definition

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, schema, &block) ⇒ undefined

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.

Initialize a new mapping instance



46
47
48
49
50
# File 'lib/rom/mapping.rb', line 46

def initialize(environment, schema, &block)
  @environment = environment
  @schema      = schema
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, &block) ⇒ Relation (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.

Method missing hook

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/rom/mapping.rb', line 59

def method_missing(name, *, &block)
  relation = schema[name]

  if relation
    build_relation(relation, &block)
  else
    super
  end
end

Class Method Details

.build(environment, schema, &block) ⇒ Hash

Build ROM relations

Examples:

relation = Axiom::Relation::Base.new(:users, [[:id, Integer], [:user_name, String]])
env      = { users: relation }

User = Class.new(OpenStruct.new)

registry = Mapping.build(env) do
  users do
    map :id
    map :user_name, to: :name
  end
end

registry[:users]
# #<ROM::Relation:0x000000025d3160>

Parameters:

Returns:

  • (Hash)


37
38
39
# File 'lib/rom/mapping.rb', line 37

def self.build(environment, schema, &block)
  new(environment, schema, &block)
end