Sha256: b466e7f4c918e0b1a8a7c836c8a31739c5d4e36b6ff741ad8a233c0bdd88419c

Contents?: true

Size: 595 Bytes

Versions: 10

Compression:

Stored size: 595 Bytes

Contents

module Kagu

  module SwiftHelper

    def self.execute(code, &block)
      tempfile = Tempfile.new
      begin
        tempfile << code
      ensure
        tempfile.close
      end
      begin
        stdout, stderr, result = Open3.capture3("swift #{tempfile.path.inspect}")
        raise(stderr.presence || "Swift command returned with code: #{result.exitstatus}") unless result.success?
        if block_given?
          stdout.lines.each { |line| yield(line.chomp) }
          nil
        else
          stdout
        end
      ensure
        tempfile.unlink
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kagu-3.0.9 lib/kagu/swift_helper.rb
kagu-3.0.8 lib/kagu/swift_helper.rb
kagu-3.0.7 lib/kagu/swift_helper.rb
kagu-3.0.6 lib/kagu/swift_helper.rb
kagu-3.0.5 lib/kagu/swift_helper.rb
kagu-3.0.4 lib/kagu/swift_helper.rb
kagu-3.0.3 lib/kagu/swift_helper.rb
kagu-3.0.2 lib/kagu/swift_helper.rb
kagu-3.0.1 lib/kagu/swift_helper.rb
kagu-3.0.0 lib/kagu/swift_helper.rb