/
composite.rb
53 lines (46 loc) · 1.07 KB
/
composite.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
50
51
52
53
# frozen_string_literal: true
require 'rom/relation/loaded'
require 'rom/relation/materializable'
require 'rom/pipeline'
module ROM
class Relation
# Left-to-right relation composition used for data-pipelining
#
# @api public
class Composite < Pipeline::Composite
include Materializable
# Call the pipeline by passing results from left to right
#
# Optional args are passed to the left object
#
# @return [Loaded]
#
# @api public
def call(*args)
relation = left.call(*args)
response = right.call(relation)
if response.is_a?(Loaded)
response
else
relation.new(response)
end
end
alias_method :[], :call
# @see Relation#map_to
#
# @api public
def map_to(klass)
self >> left.map_to(klass).mapper
end
private
# @api private
#
# @see Pipeline::Proxy#decorate?
#
# @api private
def decorate?(response)
super || response.is_a?(Graph)
end
end
end
end