Sha256: 3bb37ef224596b300b5c1b5d605249a41aace374cd155464672bca19a423342a
Contents?: true
Size: 1.76 KB
Versions: 16
Compression:
Stored size: 1.76 KB
Contents
module Eco module Common class MetaThor class Pipe SYM = "!" SYMS = [SYM] class << self #def rex_pipes # alternatives = Regex.escape(SYMS).join("|") # /(#{alternatives})/g #end def type(str) case str when SYM :standard else :unkown end end def pipe?(str) SYMS.include?(str) end def piped?(args) args.any? do |arg| pipe?(arg) end end def split(args, pipe_to_sym: false) args = (args && [args].flatten) || [] if piped?(args) args.reduce([[]]) do |groups,arg| cg = [] cg = pipe?(arg) ? cg : groups.last cg.push(arg) if arg groups.push(cg) if pipe?(arg) groups end else [].push(args) end end end attr_reader :type, :command def initialize(command:) @command = command args = @command.source_args @type = self.class.type(args.shift) end def standard? @type == :standard end def command_group command.group end def index command.index end def input_index return nil unless index > 0 case type when :standard index - 1 end end def input command_group[input_index].output if input_index end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems