Class: RedGrape::Pipe::Base
Direct Known Subclasses
AggregatePipe, AsPipe, BackPipe, BothPipe, CapPipe, CopySplitPipe, CountPipe, EPipe, ExceptPipe, ExhaustMergePipe, FillPipe, FilterPipe, GatherPipe, GroupByPipe, GroupCountPipe, HasNotPipe, HasPipe, IfThenElsePipe, InEPipe, InPipe, InVPipe, LoopPipe, MapPipe, OrderPipe, OutEPipe, OutPipe, OutVPipe, PathPipe, PropertyPipe, RetainPipe, ScatterPipe, SelectPipe, SideEffectPipe, TransformPipe, UnderscorePipe, VPipe
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(prev, *opts, &block) ⇒ Base
Returns a new instance of Base.
28
29
30
31
32
33
|
# File 'lib/red_grape/pipe/base.rb', line 28
def initialize(prev, *opts, &block)
@prev = prev
@next = nil
@opts = opts
@block = block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/red_grape/pipe/base.rb', line 140
def method_missing(name, *args, &block)
class_name = "#{name.to_s.sub(/^./){$&.upcase}.gsub(/_(.)/){$1.upcase}}Pipe"
args.unshift block if block
pipe_class =
if Pipe.const_defined? class_name
eval "RedGrape::Pipe::#{class_name}"
else
args.unshift name
PropertyPipe
end
@next = pipe_class.new self, *args
end
|
Instance Attribute Details
Returns the value of attribute it.
26
27
28
|
# File 'lib/red_grape/pipe/base.rb', line 26
def it
@it
end
|
Returns the value of attribute next.
26
27
28
|
# File 'lib/red_grape/pipe/base.rb', line 26
def next
@next
end
|
Returns the value of attribute opts.
26
27
28
|
# File 'lib/red_grape/pipe/base.rb', line 26
def opts
@opts
end
|
Returns the value of attribute prev.
26
27
28
|
# File 'lib/red_grape/pipe/base.rb', line 26
def prev
@prev
end
|
Returns the value of attribute value.
26
27
28
|
# File 'lib/red_grape/pipe/base.rb', line 26
def value
@value
end
|
Instance Method Details
#copy(depth = nil) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/red_grape/pipe/base.rb', line 128
def copy(depth=nil)
obj = self.class.new nil, @opts, &@block
if depth.nil?
obj.prev = self.prev.copy
obj.prev.next = obj
elsif 0 < depth
obj.prev = self.prev.copy(depth - 1)
obj.prev.next = obj
end
obj
end
|
#done? ⇒ Boolean
53
54
55
|
# File 'lib/red_grape/pipe/base.rb', line 53
def done?
not @value.nil?
end
|
note: both prev and next are not copied.
124
125
126
|
# File 'lib/red_grape/pipe/base.rb', line 124
def dup
self.class.new nil, @opts, &@block
end
|
#first? ⇒ Boolean
45
46
47
|
# File 'lib/red_grape/pipe/base.rb', line 45
def first?
not @prev.kind_of? RedGrape::Pipe::Base
end
|
#first_pipe ⇒ Object
39
40
41
42
43
|
# File 'lib/red_grape/pipe/base.rb', line 39
def first_pipe
pipe = self
pipe = pipe.prev until pipe.first?
pipe
end
|
#last? ⇒ Boolean
49
50
51
|
# File 'lib/red_grape/pipe/base.rb', line 49
def last?
@next.nil?
end
|
#pass_next(context, pushed_obj, next_obj = nil, &block) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/red_grape/pipe/base.rb', line 76
def pass_next(context, pushed_obj, next_obj=nil, &block)
next_obj ||= pushed_obj
if self.last?
block.call if block
next_obj
elsif pushed_obj.nil?
block.call if block
next_obj.pass_through self.next, context
else
context.push_history pushed_obj do |ctx|
block.call if block
next_obj.pass_through self.next, ctx
end
end
end
|
#pipe_eval(params = {}, &block) ⇒ Object
92
93
94
95
|
# File 'lib/red_grape/pipe/base.rb', line 92
def pipe_eval(params={}, &block)
params.each {|k, v| self.send "#{k}=", v}
instance_eval(&block)
end
|
#pipe_name ⇒ Object
35
36
37
|
# File 'lib/red_grape/pipe/base.rb', line 35
def pipe_name
self.class.name.split('::').last.sub(/Pipe$/, '')
end
|
113
114
115
116
117
118
119
120
121
|
# File 'lib/red_grape/pipe/base.rb', line 113
def size
len = 0
pipe = self
while pipe.is_a?(Pipe::Base) and pipe.prev
len += 1
pipe = pipe.prev
end
len
end
|
#take(context = Context.new) ⇒ Object
Also known as:
[]
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/red_grape/pipe/base.rb', line 57
def take(context=Context.new)
if first?
val = @prev.pass_through self, context
if context.aggregating?
context.resume_from_aggregating
elsif context.grouping?
context.resume_from_grouping
elsif context.accumulating?
context.resume_from_accumulating
else
val
end
else
@prev.take
end
end
|
103
104
105
106
107
108
109
110
111
|
# File 'lib/red_grape/pipe/base.rb', line 103
def to_a
pipe = self
ret = [pipe.pipe_name]
until pipe.first?
pipe = pipe.prev
ret.unshift pipe.pipe_name
end
ret
end
|
101
|
# File 'lib/red_grape/pipe/base.rb', line 101
def to_ary; nil end
|
97
98
99
|
# File 'lib/red_grape/pipe/base.rb', line 97
def to_s
Pipe.auto_take ? take.to_s : super
end
|