Class: ROM::Relation::ViewDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/relation/view_dsl.rb

Overview

ViewDSL is exposed in ‘Relation.view` method

This is used to establish pre-defined relation views with explicit schemas. Such views can be used to compose relations together, even from multiple adapters. In advanced adapters like rom-sql using view DSL is not required though, as relation schemas are dynamic and they always represent current tuple structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, schema) ⇒ ViewDSL

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



27
28
29
30
31
32
33
# File 'lib/rom/relation/view_dsl.rb', line 27

def initialize(name, schema, &)
  @name = name
  @schema = schema
  @new_schema = nil
  @relation_block = nil
  instance_eval(&)
end

Instance Attribute Details

#nameObject (readonly)



16
17
18
# File 'lib/rom/relation/view_dsl.rb', line 16

def name
  @name
end

#new_schemaObject (readonly)



24
25
26
# File 'lib/rom/relation/view_dsl.rb', line 24

def new_schema
  @new_schema
end

#relation_blockObject (readonly)



20
21
22
# File 'lib/rom/relation/view_dsl.rb', line 20

def relation_block
  @relation_block
end

Instance Method Details

#callArray

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 procs captured by the DSL



62
# File 'lib/rom/relation/view_dsl.rb', line 62

def call = [name, new_schema, relation_block]

#relationProc

Define a relation block for a relation view

See Also:

  • Relation::ClassInterface.view


53
54
55
# File 'lib/rom/relation/view_dsl.rb', line 53

def relation(&)
  @relation_block = proc(&)
end

#schemaProc

Define a schema for a relation view

See Also:

  • Relation::ClassInterface.view


42
43
44
# File 'lib/rom/relation/view_dsl.rb', line 42

def schema(&)
  @new_schema = -> relations { @schema.with(relations: relations).instance_exec(&) }
end