/
schema.rb
49 lines (42 loc) · 874 Bytes
/
schema.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# encoding: utf-8
module ROM
# Schema builder DSL
#
class Schema
include Concord.new(:definition), Adamantium::Flat
# Build a relation schema
#
# @example
#
# Schema.build do
# base_relation :users do
# repository :test
# attribute :id, :name
# end
# end
#
# @return [Schema]
#
# @api public
def self.build(repositories, &block)
new(Definition.new(repositories, &block))
end
# Return defined relation identified by name
#
# @example
#
# schema[:users] # => #<Axiom::Relation::Base ..>
#
# @return [Axiom::Relation, Axiom::Relation::Base]
#
# @api public
def [](name)
definition[name]
end
# @api private
def call(&block)
definition.instance_eval(&block)
self
end
end # Schema
end # ROM