Class: RedGrape::Pipe::IfThenElsePipe

Inherits:
Base show all
Defined in:
lib/red_grape/pipe/if_then_else_pipe.rb

Instance Attribute Summary

Attributes inherited from Base

#it, #next, #opts, #prev, #value

Instance Method Summary collapse

Methods inherited from Base

#copy, #done?, #dup, #first?, #first_pipe, #initialize, #last?, #method_missing, #pass_next, #pipe_eval, #pipe_name, #size, #take, #to_a, #to_ary, #to_s

Constructor Details

This class inherits a constructor from RedGrape::Pipe::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RedGrape::Pipe::Base

Instance Method Details

#pass(obj, context) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/red_grape/pipe/if_then_else_pipe.rb', line 6

def pass(obj, context)
  condition = self.opts[0]
  then_block = self.opts[1]
  else_block = self.opts[2]
  ret =
    if context.eval({:it => obj}, &condition)
      context.eval({:it => obj}, &then_block)
    else
      context.eval({:it => obj}, &else_block)
    end
  ret = ret.take if ret.is_a? Pipe::Base
  pass_next context, ret
end