Module: Pacer::Transform::Branch
- Defined in:
- lib/pacer/transform/branch.rb
Instance Attribute Summary collapse
-
#branches ⇒ Object
Returns the value of attribute branches.
-
#conds ⇒ Object
Returns the value of attribute conds.
-
#merge_pipe_class ⇒ Object
Returns the value of attribute merge_pipe_class.
-
#split_pipe_class ⇒ Object
Returns the value of attribute split_pipe_class.
Instance Method Summary collapse
- #add_block!(&block) ⇒ Object
- #add_cond!(where, &block) ⇒ Object
- #after_initialize ⇒ Object
- #attach_pipe(end_pipe) ⇒ Object
- #branch(&block) ⇒ Object
- #clone(conf = {}) ⇒ Object
- #cond(where, &block) ⇒ Object
- #merge ⇒ Object
- #merge_exhaustive ⇒ Object
- #otherwise(&block) ⇒ Object
Instance Attribute Details
#branches ⇒ Object
Returns the value of attribute branches.
34 35 36 |
# File 'lib/pacer/transform/branch.rb', line 34 def branches @branches end |
#conds ⇒ Object
Returns the value of attribute conds.
34 35 36 |
# File 'lib/pacer/transform/branch.rb', line 34 def conds @conds end |
#merge_pipe_class ⇒ Object
Returns the value of attribute merge_pipe_class.
34 35 36 |
# File 'lib/pacer/transform/branch.rb', line 34 def merge_pipe_class @merge_pipe_class end |
#split_pipe_class ⇒ Object
Returns the value of attribute split_pipe_class.
34 35 36 |
# File 'lib/pacer/transform/branch.rb', line 34 def split_pipe_class @split_pipe_class end |
Instance Method Details
#add_block!(&block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pacer/transform/branch.rb', line 82 def add_block!(&block) will_clone = false branch = block.call(Pacer::Route.empty(back)) branches.push branch conf = {} exts = branches. map { |b| b.extensions }. map { |a| a ? a.to_set : Set[] }. reduce { |r, e| r.intersection(e) } if exts.to_a != config[:extensions] conf[:extensions] = exts.to_a end types = branches.map { |b| b.element_type }.to_set if types.length == 1 type = types.first elsif types.difference([:vertex, :edge, :mixed]).empty? type = :mixed elsif types.difference([:path, :array]).empty? type = :array else type = :object end if type != element_type conf[:element_type] = type end if conf.empty? self else clone conf end end |
#add_cond!(where, &block) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/pacer/transform/branch.rb', line 116 def add_cond!(where, &block) conds[branches.length] = where add_block! do |r| block.call r.where(where) end end |
#after_initialize ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/pacer/transform/branch.rb', line 36 def after_initialize super self.branches ||= [] self.conds ||= [] self.split_pipe_class ||= CopySplitPipe self.merge_pipe_class ||= FairMergePipe end |
#attach_pipe(end_pipe) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/pacer/transform/branch.rb', line 123 def attach_pipe(end_pipe) branch_pipes = branches.map { |b| Pacer::Route.pipeline(b) } split = split_pipe_class.new branch_pipes merge = merge_pipe_class.new branch_pipes merge.setStarts split if end_pipe split.setStarts end_pipe merge else Pacer::Pipes::BlackboxPipeline.new split, merge end end |
#branch(&block) ⇒ Object
55 56 57 58 |
# File 'lib/pacer/transform/branch.rb', line 55 def branch(&block) route = clone route.add_block! &block end |
#clone(conf = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pacer/transform/branch.rb', line 44 def clone(conf = {}) back.chain_route({transform: Branch, branches: branches.clone, element_type: element_type, conds: conds.clone, extensions: extensions.clone, split_pipe_class: split_pipe_class, merge_pipe_class: merge_pipe_class }.merge(conf)) end |
#cond(where, &block) ⇒ Object
60 61 62 63 |
# File 'lib/pacer/transform/branch.rb', line 60 def cond(where, &block) route = clone route.add_cond! where, &block end |
#merge ⇒ Object
70 71 72 73 74 |
# File 'lib/pacer/transform/branch.rb', line 70 def merge route = clone route.merge_pipe_class = FairMergePipe route.chain_route transform: MergedBranch end |
#merge_exhaustive ⇒ Object
76 77 78 79 80 |
# File 'lib/pacer/transform/branch.rb', line 76 def merge_exhaustive route = clone route.merge_pipe_class = ExhaustMergePipe route.chain_route transform: MergedBranch end |
#otherwise(&block) ⇒ Object
65 66 67 68 |
# File 'lib/pacer/transform/branch.rb', line 65 def otherwise(&block) where = "(#{ conds.compact.map { |c| "not (#{c})" }.join " and " })" cond where, &block end |