Class: Konstant::Project

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Project

Returns a new instance of Project.



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

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/konstant/project.rb', line 7

def id
  @id
end

Class Method Details

.allObject



9
10
11
12
13
# File 'lib/konstant/project.rb', line 9

def self.all
  Dir["#{Konstant.config['data_dir']}/projects/*"].map do |path|
    new path.split('/').last
  end
end

Instance Method Details

#as_jsonObject



61
62
63
64
65
66
67
68
69
# File 'lib/konstant/project.rb', line 61

def as_json(*)
  return {
    "id" => id,
    "ok" => ok?,
    "deploy_ok" => ok?('deploy'),
    "cleanup_ok" => ok?('cleanup'),
    "building" => building?
  }
end

#build!Object



15
16
17
# File 'lib/konstant/project.rb', line 15

def build!
  system "touch #{path}/run.txt"
end

#build_timestampsObject



27
28
29
30
31
# File 'lib/konstant/project.rb', line 27

def build_timestamps
  Dir["#{path}/builds/*"].map do |path|
    path.split('/').last
  end.sort.reverse
end

#building?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/konstant/project.rb', line 19

def building?
  File.exists? "#{path}/running.txt"
end

#buildsObject



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

def builds
  build_timestamps.map do |ts|
    Konstant::Build.new self, ts
  end
end

#last_buildObject



39
40
41
42
43
# File 'lib/konstant/project.rb', line 39

def last_build
  if ts = build_timestamps.first
    Konstant::Build.new self, ts
  end
end

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

Returns:

  • (Boolean)


45
46
47
# File 'lib/konstant/project.rb', line 45

def ok?(task = 'build')
  last_build && last_build.ok?(task)
end

#pathObject



23
24
25
# File 'lib/konstant/project.rb', line 23

def path
  "#{Konstant.config['data_dir']}/projects/#{id}"
end

#status(task = 'build') ⇒ Object



49
50
51
# File 'lib/konstant/project.rb', line 49

def status(task = 'build')
  last_build ? last_build.status(task) : nil
end

#stderr(task = 'build') ⇒ Object



57
58
59
# File 'lib/konstant/project.rb', line 57

def stderr(task = 'build')
  last_build ? last_build.stderr(task) : nil
end

#stdout(task = 'build') ⇒ Object



53
54
55
# File 'lib/konstant/project.rb', line 53

def stdout(task = 'build')
  last_build ? last_build.stdout(task) : nil
end

#to_json(*args) ⇒ Object



71
72
73
# File 'lib/konstant/project.rb', line 71

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