Sha256: 56c19e12da57a790a39b8b277bc44e83a5209f70d8c04c0f4c6b21549e5181c0

Contents?: true

Size: 457 Bytes

Versions: 2

Compression:

Stored size: 457 Bytes

Contents

require 'ansi/code'

module Space
  class Command
    attr_reader :path, :command

    def initialize(path, command)
      @path = File.expand_path(path)
      @command = command
    end

    def result
      @result ||= chdir { strip_ansi(`#{command}`) }
    end

    def reset
      @result = nil
    end

    def chdir(&block)
      Dir.chdir(path, &block)
    end

    def strip_ansi(string)
      string.gsub(ANSI::Code::PATTERN, '')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
space-0.0.3 lib/space/models/command.rb
space-0.0.2 lib/space/models/command.rb