Class: ROM::Schema::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/schema/definition.rb,
lib/rom/schema/definition/relation.rb,
lib/rom/schema/definition/relation/base.rb

Overview

Builder object used by schema DSL to establish Axiom relations

Defined Under Namespace

Classes: Relation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repositories, &block) ⇒ Definition

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 Definition.



15
16
17
18
19
# File 'lib/rom/schema/definition.rb', line 15

def initialize(repositories, &block)
  @repositories = repositories
  @relations    = {}
  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Axiom::Relation, Axiom::Relation::Base (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:

  • (Axiom::Relation, Axiom::Relation::Base)


75
76
77
# File 'lib/rom/schema/definition.rb', line 75

def method_missing(name)
  self[name] || super
end

Instance Attribute Details

#relationsObject (readonly)

Returns the value of attribute relations.



12
13
14
# File 'lib/rom/schema/definition.rb', line 12

def relations
  @relations
end

#repositoriesObject (readonly)

Returns the value of attribute repositories.



12
13
14
# File 'lib/rom/schema/definition.rb', line 12

def repositories
  @repositories
end

Instance Method Details

#[](name) ⇒ Axiom::Relation, Axiom::Relation::Base

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 relation identified by name

Returns:

  • (Axiom::Relation, Axiom::Relation::Base)


64
65
66
# File 'lib/rom/schema/definition.rb', line 64

def [](name)
  relations[name]
end

#base_relation(name, &block) ⇒ Definition

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.

Build a base relation

Examples:


Schema.build do
  base_relation :users do
    # ...
  end
end

Returns:



34
35
36
37
38
39
40
# File 'lib/rom/schema/definition.rb', line 34

def base_relation(name, &block)
  builder    = Relation::Base.new(&block)
  repository = repositories.fetch(builder.repository)

  repository[name] = builder.call(name)
  relations[name]  = repository[name]
end

#relation(name, &block) ⇒ Definition

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.

Build a relation

Examples:


Schema.build do
  relation :users do
    # ...
  end
end

Returns:



55
56
57
# File 'lib/rom/schema/definition.rb', line 55

def relation(name, &block)
  relations[name] = instance_eval(&block)
end