Class: ROM::Relation::ViewDSL
- Inherits:
-
Object
- Object
- ROM::Relation::ViewDSL
- 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
- #name ⇒ Object readonly
- #new_schema ⇒ Object readonly
- #relation_block ⇒ Object readonly
Instance Method Summary collapse
-
#call ⇒ Array
private
Return procs captured by the DSL.
-
#initialize(name, schema, &block) ⇒ ViewDSL
constructor
private
A new instance of ViewDSL.
-
#relation(&block) ⇒ Proc
Define a relation block for a relation view.
-
#schema(&block) ⇒ Proc
Define a schema for a relation view.
Constructor Details
#initialize(name, schema, &block) ⇒ 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.
25 26 27 28 29 30 31 |
# File 'lib/rom/relation/view_dsl.rb', line 25 def initialize(name, schema, &block) @name = name @schema = schema @new_schema = nil @relation_block = nil instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
14 15 16 |
# File 'lib/rom/relation/view_dsl.rb', line 14 def name @name end |
#new_schema ⇒ Object (readonly)
22 23 24 |
# File 'lib/rom/relation/view_dsl.rb', line 22 def new_schema @new_schema end |
#relation_block ⇒ Object (readonly)
18 19 20 |
# File 'lib/rom/relation/view_dsl.rb', line 18 def relation_block @relation_block end |
Instance Method Details
#call ⇒ Array
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
60 61 62 |
# File 'lib/rom/relation/view_dsl.rb', line 60 def call [name, new_schema, relation_block] end |
#relation(&block) ⇒ Proc
Define a relation block for a relation view
51 52 53 |
# File 'lib/rom/relation/view_dsl.rb', line 51 def relation(&block) @relation_block = lambda(&block) end |
#schema(&block) ⇒ Proc
Define a schema for a relation view
40 41 42 |
# File 'lib/rom/relation/view_dsl.rb', line 40 def schema(&block) @new_schema = -> relations { @schema.with(relations: relations).instance_exec(&block) } end |