Class: AppQuery::RowBuilder
- Inherits:
-
Object
- Object
- AppQuery::RowBuilder
- Defined in:
- lib/app_query.rb
Overview
Composable pipeline of row transformers.
Appended via << and applied in registration order — earliest pushed
runs first, latest pushed runs last (so its return value is what callers
see). An empty pipeline is a no-op.
Instance Method Summary collapse
-
#<<(callable) ⇒ Object
Append a transformer.
- #call(row) ⇒ Object
-
#dup ⇒ Object
Independent copy — used by Q#deep_dup so chained queries don't share the parent's pipeline.
- #empty? ⇒ Boolean
-
#initialize(procs = []) ⇒ RowBuilder
constructor
A new instance of RowBuilder.
- #size ⇒ Object
Constructor Details
#initialize(procs = []) ⇒ RowBuilder
Returns a new instance of RowBuilder.
170 171 172 |
# File 'lib/app_query.rb', line 170 def initialize(procs = []) @procs = procs end |
Instance Method Details
#<<(callable) ⇒ Object
Append a transformer. Returns self so q.row_builder << proc reads
naturally and <<= also works.
176 177 178 179 |
# File 'lib/app_query.rb', line 176 def <<(callable) @procs << callable self end |
#call(row) ⇒ Object
181 182 183 |
# File 'lib/app_query.rb', line 181 def call(row) @procs.reduce(row) { |acc, p| p.call(acc) } end |
#dup ⇒ Object
Independent copy — used by Q#deep_dup so chained queries don't share the parent's pipeline.
191 192 193 |
# File 'lib/app_query.rb', line 191 def dup self.class.new(@procs.dup) end |
#empty? ⇒ Boolean
185 |
# File 'lib/app_query.rb', line 185 def empty? = @procs.empty? |
#size ⇒ Object
187 |
# File 'lib/app_query.rb', line 187 def size = @procs.size |