Sha256: e28494225b9665f62389a38c13db89eb2254ea84416f29fa9c6893b8a988396d

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require "bundler"

class Konstant::Runner

  def initialize(build, task)
    @build = build
    @task = task
  end

  attr_reader :build, :task

  def run
    if task == "build" || File.exists?("#{build.project.path}/#{task}")
      duration = Konstant.measure do
        build.create
        File.open status_file, "w" do |f|
          ::Bundler.with_clean_env do
            system environment, "#{build.project.path}/#{task} > #{stdout_file} 2> #{stderr_file}"
            f.puts $?.exitstatus
          end
        end
      end
      File.open "#{build.path}/#{task}.duration", "w" do |f|
        f.puts duration
      end

      build.status(task) == 0
    else
      false
    end
  end

  def environment
    return {
      "KONSTANT_PROJECT_ROOT" => File.expand_path(build.project.path),
      "KONSTANT_TIMESTAMP" => build.timestamp
    }
  end

  def stdout_file
    "#{build.path}/#{task}.stdout"
  end

  def stderr_file
    "#{build.path}/#{task}.stderr"
  end

  def status_file
    "#{build.path}/#{task}.status"
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
konstant-0.1.2 lib/konstant/runner.rb
konstant-0.1.1 lib/konstant/runner.rb
konstant-0.1.0 lib/konstant/runner.rb
konstant-0.0.10 lib/konstant/runner.rb