Class: Cerberus::Status
- Inherits:
-
Object
- Object
- Cerberus::Status
- Defined in:
- lib/cerberus/manager.rb
Overview
Fields that are contained in status file
successful_build_timestamp
timestamp
successful (true mean previous build was successful, otherwise - false)
revision
brokeness
successful_build_revision
Instance Attribute Summary collapse
-
#current_brokeness ⇒ Object
readonly
Returns the value of attribute current_brokeness.
-
#current_build_successful ⇒ Object
readonly
Returns the value of attribute current_build_successful.
-
#previous_brokeness ⇒ Object
readonly
Returns the value of attribute previous_brokeness.
-
#previous_build_successful ⇒ Object
readonly
Returns the value of attribute previous_build_successful.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#successful_build_revision ⇒ Object
readonly
Returns the value of attribute successful_build_revision.
Class Method Summary collapse
Instance Method Summary collapse
- #current_state ⇒ Object
-
#initialize(param) ⇒ Status
constructor
A new instance of Status.
- #keep(build_successful, revision, brokeness) ⇒ Object
Constructor Details
#initialize(param) ⇒ Status
Returns a new instance of Status.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/cerberus/manager.rb', line 291 def initialize(param) if param.is_a? Hash @hash = param @current_build_successful = @hash['state'] @already_kept = true else @path = param value = File.exists?(@path) ? YAML.load(IO.read(@path)) : nil @hash = case value when String value = %w(succesful successful setup).include?(value) #fix typo in status values {'successful' => value} when nil {} else value end @already_kept = false end @revision = @hash['revision'] @successful_build_revision = @hash['successful_build_revision'] @previous_build_successful = @hash['successful'] @previous_brokeness = @hash['brokeness'] # Create some convenience methods to access status @hash.keys.each { |key| self.class.send( :define_method, key ) { @hash[key] } } end |
Instance Attribute Details
#current_brokeness ⇒ Object (readonly)
Returns the value of attribute current_brokeness.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def current_brokeness @current_brokeness end |
#current_build_successful ⇒ Object (readonly)
Returns the value of attribute current_build_successful.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def current_build_successful @current_build_successful end |
#previous_brokeness ⇒ Object (readonly)
Returns the value of attribute previous_brokeness.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def previous_brokeness @previous_brokeness end |
#previous_build_successful ⇒ Object (readonly)
Returns the value of attribute previous_build_successful.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def previous_build_successful @previous_build_successful end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def revision @revision end |
#successful_build_revision ⇒ Object (readonly)
Returns the value of attribute successful_build_revision.
289 290 291 |
# File 'lib/cerberus/manager.rb', line 289 def successful_build_revision @successful_build_revision end |
Class Method Details
Instance Method Details
#current_state ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/cerberus/manager.rb', line 347 def current_state raise "Invalid project state. Before calculating status please do keeping of it." unless @already_kept if @current_build_successful if @previous_build_successful.nil? :setup else @previous_build_successful ? :successful : :revival end else @previous_build_successful ? :failed : :broken end end |
#keep(build_successful, revision, brokeness) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/cerberus/manager.rb', line 327 def keep(build_successful, revision, brokeness) raise 'Status could be kept only once. Please try to reread status file.' if @already_kept @current_brokeness = brokeness @current_build_successful = build_successful hash = {'successful' => @current_build_successful, 'timestamp' => Time.now, 'revision' => revision, 'brokeness' => brokeness} if build_successful hash['successful_build_timestamp'] = Time.now hash['successful_build_revision'] = revision else hash['successful_build_timestamp'] = @hash['successful_build_timestamp'] hash['successful_build_revision'] = @hash['successful_build_revision'] end File.open(@path, "w+", 0777) { |file| file.write(YAML.dump(hash)) } @already_kept = true end |