Class: Konstant::Build

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, timestamp) ⇒ Build

Returns a new instance of Build.



3
4
5
6
# File 'lib/konstant/build.rb', line 3

def initialize(project, timestamp)
  @project = project
  @timestamp = timestamp
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



8
9
10
# File 'lib/konstant/build.rb', line 8

def project
  @project
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



8
9
10
# File 'lib/konstant/build.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#as_jsonObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/konstant/build.rb', line 60

def as_json(*)
  return {
    "project_id" => project.id,
    "timestamp" => timestamp,
    "human" => human,
    "stdout" => stdout,
    "stderr" => stderr,
    "status" => status,
    "ok" => ok?,
    "deploy" => {
      "stdout" => stdout('deploy'),
      "stderr" => stderr('deploy'),
      "status" => status('deploy')
    },
    "cleanup" => {
      "stdout" => stdout('cleanup'),
      "stderr" => stderr('cleanup'),
      "status" => status('cleanup')
    }
  }
end

#createObject



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

def create
  system "mkdir -p #{path}"
end

#destroyObject



14
15
16
# File 'lib/konstant/build.rb', line 14

def destroy
  system "rm -rf #{path}"
end

#failure?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/konstant/build.rb', line 26

def failure?
  !ok?
end

#humanObject



18
19
20
# File 'lib/konstant/build.rb', line 18

def human
  Time.parse(timestamp).strftime("%Y-%m-%d %H:%M:%S")
end

#ok?(task = 'build') ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/konstant/build.rb', line 22

def ok?(task = 'build')
  status(task) == nil ? nil : (status(task) == 0)
end

#pathObject



30
31
32
# File 'lib/konstant/build.rb', line 30

def path
  "#{project.path}/builds/#{timestamp}"
end

#previousObject



52
53
54
55
56
57
58
# File 'lib/konstant/build.rb', line 52

def previous
  timestamps = project.build_timestamps
  index = timestamps.index(timestamp)
  if index <= timestamps.size - 1
    project.builds[index + 1]
  end
end

#status(task = 'build') ⇒ Object



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

def status(task = 'build')
  File.read("#{path}/#{task}.status").strip.to_i
rescue Errno::ENOENT => e
  nil
end

#stderr(task = 'build') ⇒ Object



46
47
48
49
50
# File 'lib/konstant/build.rb', line 46

def stderr(task = 'build')
  File.read "#{path}/#{task}.stderr"
rescue Errno::ENOENT => e
  nil
end

#stdout(task = 'build') ⇒ Object



40
41
42
43
44
# File 'lib/konstant/build.rb', line 40

def stdout(task = 'build')
  File.read "#{path}/#{task}.stdout"
rescue Errno::ENOENT => e
  nil
end

#to_json(*args) ⇒ Object



82
83
84
# File 'lib/konstant/build.rb', line 82

def to_json(*args)
  as_json.to_json(*args)
end