class PipeOperator::Pipe
Public Class Methods
new(object, *args)
click to toggle source
Calls superclass method
# File lib/pipe_operator/pipe.rb 9 def self.new(object, *args) 10 if block_given? 11 super.__call__ 12 elsif args.none? || Closure === args[0] 13 super 14 else 15 super(object).__send__(*args) 16 end 17 end
new(object, *args, &block)
click to toggle source
# File lib/pipe_operator/pipe.rb 27 def initialize(object, *args, &block) 28 @args = args 29 @block = block 30 @object = object 31 @pipeline = [] 32 end
open(pipe = nil) { |: last| ... }
click to toggle source
# File lib/pipe_operator/pipe.rb 19 def self.open(pipe = nil) 20 @pipeline ||= [] 21 @pipeline << pipe if pipe 22 block_given? ? yield : @pipeline.last 23 ensure 24 @pipeline.pop if pipe 25 end
Public Instance Methods
__call__()
click to toggle source
# File lib/pipe_operator/pipe.rb 34 def __call__ 35 if defined?(@pipe) 36 return @pipe 37 elsif @block 38 ProxyResolver.new(::Object).proxy 39 @args.each { |arg| ProxyResolver.new(arg).proxy } 40 Pipe.open(self) { instance_exec(*@args, &@block) } 41 end 42 43 @pipe = @object 44 @pipeline.each { |closure| @pipe = closure.call(@pipe) } 45 @pipe 46 end
inspect()
click to toggle source
# File lib/pipe_operator/pipe.rb 48 def inspect 49 return method_missing(__method__) if Pipe.open 50 inspect = ::PipeOperator.inspect(@object) 51 "#<#{Pipe.name}:#{inspect}>" 52 end
Protected Instance Methods
__pop__(pipe)
click to toggle source
# File lib/pipe_operator/pipe.rb 56 def __pop__(pipe) 57 index = @pipeline.rindex(pipe) 58 @pipeline.delete_at(index) if index 59 end
__push__(pipe)
click to toggle source
# File lib/pipe_operator/pipe.rb 61 def __push__(pipe) 62 @pipeline << pipe 63 pipe 64 end
|(*)
click to toggle source
# File lib/pipe_operator/pipe.rb 66 def |(*) 67 self 68 end
Private Instance Methods
method_missing(method, *curry, &block)
click to toggle source
# File lib/pipe_operator/pipe.rb 72 def method_missing(method, *curry, &block) 73 closure = Closure.new(self, method, *curry, &block) 74 75 pipe = Pipe.open 76 pipe && [*curry, block].each { |o| pipe.__pop__(o) } 77 78 if pipe == self 79 __push__(closure.__shift__) 80 elsif pipe 81 pipe.__push__(closure) 82 else 83 closure 84 end 85 end