Class: Konstant::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/konstant/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build, task) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
# File 'lib/konstant/runner.rb', line 5

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

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



10
11
12
# File 'lib/konstant/runner.rb', line 10

def build
  @build
end

#taskObject (readonly)

Returns the value of attribute task.



10
11
12
# File 'lib/konstant/runner.rb', line 10

def task
  @task
end

Instance Method Details

#environmentObject



33
34
35
36
37
38
# File 'lib/konstant/runner.rb', line 33

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

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/konstant/runner.rb', line 12

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

#status_fileObject



48
49
50
# File 'lib/konstant/runner.rb', line 48

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

#stderr_fileObject



44
45
46
# File 'lib/konstant/runner.rb', line 44

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

#stdout_fileObject



40
41
42
# File 'lib/konstant/runner.rb', line 40

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