Sha256: 82c23717831197d823fbb7a20b38d099285b26e1a2a2dc1f8022c4c2e5f4eb8e

Contents?: true

Size: 960 Bytes

Versions: 4

Compression:

Stored size: 960 Bytes

Contents

module GemSuit
  class CLI < Thor
    module Application
      class IOBuffer

        def self.capture(&block)
          self.new.capture &block
        end

        def capture(&block)
          @data = nil
          data.record do
            yield self
          end
        end

        def log(line)
          data << "GemSuit: #{line}"
        end

        def execute(command)
          IO.popen(command) do |io|
            until io.eof?
              puts (data << io.gets).last
            end
          end
        end

      private

        def data
          @data ||= BufferData.new
        end

        class BufferData
          attr_reader :output, :start, :finish

          def record(&block)
            @output = []
            @start  = Time.now
            yield
            @finish = Time.now
            self
          end

          def <<(string)
            @output << string
          end
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gem_suit-0.1.3 lib/gem_suit/cli/application/io_buffer.rb
gem_suit-0.1.2 lib/gem_suit/cli/application/io_buffer.rb
gem_suit-0.1.1 lib/gem_suit/cli/application/io_buffer.rb
gem_suit-0.1.0 lib/gem_suit/cli/application/io_buffer.rb