Class: Konstant::Build
- Inherits:
-
Object
- Object
- Konstant::Build
- Defined in:
- lib/konstant/build.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #as_json ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #failure? ⇒ Boolean
- #human ⇒ Object
-
#initialize(project, timestamp) ⇒ Build
constructor
A new instance of Build.
- #ok?(task = 'build') ⇒ Boolean
- #path ⇒ Object
- #previous ⇒ Object
- #status(task = 'build') ⇒ Object
- #stderr(task = 'build') ⇒ Object
- #stdout(task = 'build') ⇒ Object
- #to_json(*args) ⇒ Object
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, ) @project = project @timestamp = end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
8 9 10 |
# File 'lib/konstant/build.rb', line 8 def project @project end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
8 9 10 |
# File 'lib/konstant/build.rb', line 8 def @timestamp end |
Instance Method Details
#as_json ⇒ Object
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" => , "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 |
#create ⇒ Object
10 11 12 |
# File 'lib/konstant/build.rb', line 10 def create system "mkdir -p #{path}" end |
#destroy ⇒ Object
14 15 16 |
# File 'lib/konstant/build.rb', line 14 def destroy system "rm -rf #{path}" end |
#failure? ⇒ Boolean
26 27 28 |
# File 'lib/konstant/build.rb', line 26 def failure? !ok? end |
#human ⇒ Object
18 19 20 |
# File 'lib/konstant/build.rb', line 18 def human Time.parse().strftime("%Y-%m-%d %H:%M:%S") end |
#ok?(task = 'build') ⇒ Boolean
22 23 24 |
# File 'lib/konstant/build.rb', line 22 def ok?(task = 'build') status(task) == nil ? nil : (status(task) == 0) end |
#path ⇒ Object
30 31 32 |
# File 'lib/konstant/build.rb', line 30 def path "#{project.path}/builds/#{}" end |
#previous ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/konstant/build.rb', line 52 def previous = project. index = .index() if index <= .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 |