Sha256: 07c6ad0b1d0e0ceaceafd96ec6e95157d5370bf17e72ad4eb511d872f4c655f9

Contents?: true

Size: 641 Bytes

Versions: 13

Compression:

Stored size: 641 Bytes

Contents

class Cl
  module Runner
    class Multi
      attr_reader :name, :cmds

      def initialize(name, *args)
        @name = name
        @cmds = build(group(args))
      end

      def run
        cmds.map(&:run)
      end

      private

        def group(args, cmds = [])
          args.flatten.map(&:to_s).inject([[]]) do |cmds, arg|
            cmd = Cmd.registered?(arg) ? Cmd[arg] : nil
            cmd ? cmds << [cmd] : cmds.last << arg
            cmds.reject(&:empty?)
          end
        end

        def build(cmds)
          cmds.map do |(cmd, *args)|
            cmd.new(name, args)
          end
        end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cl-0.1.12 lib/cl/runner/multi.rb
cl-0.1.11 lib/cl/runner/multi.rb
cl-0.1.10 lib/cl/runner/multi.rb
cl-0.1.9 lib/cl/runner/multi.rb
cl-0.1.8 lib/cl/runner/multi.rb
cl-0.1.7 lib/cl/runner/multi.rb
cl-0.1.6 lib/cl/runner/multi.rb
cl-0.1.5 lib/cl/runner/multi.rb
cl-0.1.4 lib/cl/runner/multi.rb
cl-0.1.3 lib/cl/runner/multi.rb
cl-0.1.2 lib/cl/runner/multi.rb
cl-0.1.1 lib/cl/runner/multi.rb
cl-0.1.0 lib/cl/runner/multi.rb