class ROM::Relation::ViewDSL

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.

@api public

Attributes

name[R]

@!attribute [r] name

@return [Symbol] The view name (relation method)
new_schema[R]

@!attribute [r] new_schema

@return [Proc] The schema proc returned by the schema DSL
relation_block[R]

@!attribute [r] relation_block

@return [Proc] The relation block that will be evaluated by the view method

Public Class Methods

new(name, schema, &block) click to toggle source

@api private

# File lib/rom/relation/view_dsl.rb, line 27
def initialize(name, schema, &block)
  @name = name
  @schema = schema
  @new_schema = nil
  @relation_block = nil
  instance_eval(&block)
end

Public Instance Methods

call() click to toggle source

Return procs captured by the DSL

@return [Array]

@api private

# File lib/rom/relation/view_dsl.rb, line 62
def call
  [name, new_schema, relation_block]
end
relation(&block) click to toggle source

Define a relation block for a relation view

@return [Proc]

@see Relation::ClassInterface.view

@api public

# File lib/rom/relation/view_dsl.rb, line 53
def relation(&block)
  @relation_block = proc(&block)
end
schema(&block) click to toggle source

Define a schema for a relation view

@return [Proc]

@see Relation::ClassInterface.view

@api public

# File lib/rom/relation/view_dsl.rb, line 42
def schema(&block)
  @new_schema = -> relations { @schema.with(relations: relations).instance_exec(&block) }
end