Class: Kaya::Suites::Suite
- Inherits:
-
Object
- Object
- Kaya::Suites::Suite
- Defined in:
- lib/kaya/suites/suite.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#command ⇒ Object
Returns the value of attribute command.
-
#custom ⇒ Object
Returns the value of attribute custom.
-
#id ⇒ Object
Returns the value of attribute id.
-
#info ⇒ Object
Returns the value of attribute info.
-
#last_execution ⇒ Object
Returns the value of attribute last_execution.
-
#last_result ⇒ Object
Returns the value of attribute last_result.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #activate! ⇒ Object
- #all_results ⇒ Object
- #all_results_ids ⇒ Object
- #api_response ⇒ Object
-
#check_last_result! ⇒ Object
If test suites ir running.
- #deactivate! ⇒ Object
- #has_custom_params? ⇒ Boolean
- #has_info? ⇒ Boolean
- #has_results? ⇒ Boolean
-
#initialize(suite_data = nil) ⇒ Suite
constructor
First, try to get suite info from mongo.
- #is_ready? ⇒ Boolean
- #is_running? ⇒ Boolean
- #number_of_results ⇒ Object
-
#required_custom_params ⇒ Array
Returns an array of those required custom params This is for start execution validations.
- #save! ⇒ Object
- #set_ready! ⇒ Object
- #set_running! ⇒ Object
- #suite_data_for(suite_name) ⇒ Object
-
#suite_data_structure ⇒ Hash
Returns the structure of a suite data.
Constructor Details
#initialize(suite_data = nil) ⇒ Suite
First, try to get suite info from mongo. If it does not exist creates a new one with default values
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kaya/suites/suite.rb', line 18 def initialize suite_data = nil $K_LOG.debug "[#{suite_data["_id"]}:#{suite_data["name"]}] Creating suite object " if $K_LOG if suite_data.is_a? Hash @id = suite_data["_id"] @name = suite_data["name"] @branch = suite_data["branch"] @status = suite_data["status"] @command = suite_data["command"] @custom = suite_data["custom"] || [] @info = suite_data["info"] || "" @last_execution = suite_data["last_execution"] @last_result = suite_data["last_result"] @active = suite_data["active"] else $K_LOG.error "Creting suite object. Argument is not a hash" if $K_LOG raise "Suite data not defined correctly. Expecting info about suite" end end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def active @active end |
#branch ⇒ Object
Returns the value of attribute branch.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def branch @branch end |
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def command @command end |
#custom ⇒ Object
Returns the value of attribute custom.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def custom @custom end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def id @id end |
#info ⇒ Object
Returns the value of attribute info.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def info @info end |
#last_execution ⇒ Object
Returns the value of attribute last_execution.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def last_execution @last_execution end |
#last_result ⇒ Object
Returns the value of attribute last_result.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def last_result @last_result end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/kaya/suites/suite.rb', line 5 def status @status end |
Class Method Details
.get(suite_id) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/kaya/suites/suite.rb', line 48 def self.get suite_id $K_LOG.debug "Getting suite data for [id:#{suite_id}]" if $K_LOG suite_data = Kaya::Database::MongoConnector.suite_data_for suite_id suite_data = suite_data.to_h if respond_to? :to_h new(suite_data) if suite_data end |
.get_suite_with(name) ⇒ Object
55 56 57 |
# File 'lib/kaya/suites/suite.rb', line 55 def self.get_suite_with name self.new(Kaya::Database::MongoConnector.suite_data_for_name(name)) end |
.new_suite(suite_name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kaya/suites/suite.rb', line 59 def self.new_suite(suite_name) $K_LOG.debug "Defining new suite [#{suite_name}]" if $K_LOG suite_data = { "_id" => Kaya::Database::MongoConnector.generate_id, "name" => suite_name, "branch" => Kaya::Support::Git.actual_branch, "status" => "READY", "active" => true } self.new(suite_data) end |
Instance Method Details
#activate! ⇒ Object
108 109 110 111 112 |
# File 'lib/kaya/suites/suite.rb', line 108 def activate! @active= true $K_LOG.debug "[#{@id}:#{@name}] Activated" if $K_LOG self.save! end |
#all_results ⇒ Object
148 149 150 |
# File 'lib/kaya/suites/suite.rb', line 148 def all_results Kaya::Database::MongoConnector.results_for(id) end |
#all_results_ids ⇒ Object
144 145 146 |
# File 'lib/kaya/suites/suite.rb', line 144 def all_results_ids all_results.inject([]){|res, result| res << result["_id"]} end |
#api_response ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/kaya/suites/suite.rb', line 39 def api_response response = suite_data_structure response["results"]={ "size" => number_of_results, "ids" => all_results_ids } response end |
#check_last_result! ⇒ Object
If test suites ir running
166 167 168 169 170 171 172 |
# File 'lib/kaya/suites/suite.rb', line 166 def check_last_result! if self.is_running? and (result = Results::Result.get(@last_result)) $K_LOG.debug "[#{@id}:#{@name}] Checking last result" if $K_LOG self.set_ready! if (result.update_values! or result.finished?) $K_LOG.debug "[#{@id}:#{@name}] Done" if $K_LOG end end |
#deactivate! ⇒ Object
114 115 116 117 118 |
# File 'lib/kaya/suites/suite.rb', line 114 def deactivate! @active = false $K_LOG.debug "[#{@id}:#{@name}] Deactivated" if $K_LOG self.save! end |
#has_custom_params? ⇒ Boolean
93 94 95 |
# File 'lib/kaya/suites/suite.rb', line 93 def has_custom_params? !@custom.empty? end |
#has_info? ⇒ Boolean
104 105 106 |
# File 'lib/kaya/suites/suite.rb', line 104 def has_info? not @info.empty? end |
#has_results? ⇒ Boolean
152 153 154 |
# File 'lib/kaya/suites/suite.rb', line 152 def has_results? number_of_results > 0 end |
#is_ready? ⇒ Boolean
120 121 122 |
# File 'lib/kaya/suites/suite.rb', line 120 def is_ready? status == "READY" end |
#is_running? ⇒ Boolean
124 125 126 |
# File 'lib/kaya/suites/suite.rb', line 124 def is_running? status == "RUNNING" end |
#number_of_results ⇒ Object
140 141 142 |
# File 'lib/kaya/suites/suite.rb', line 140 def number_of_results all_results.size end |
#required_custom_params ⇒ Array
Returns an array of those required custom params This is for start execution validations
100 101 102 |
# File 'lib/kaya/suites/suite.rb', line 100 def required_custom_params custom.select{|param| param["required"]}.map{|param| param["name"]} end |
#save! ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/kaya/suites/suite.rb', line 156 def save! if Kaya::Database::MongoConnector.suite_data_for(id) Kaya::Database::MongoConnector.update_suite(suite_data_structure) else Kaya::Database::MongoConnector.insert_suite(suite_data_structure) end $K_LOG.debug "[#{@id}:#{@name}] Suite saved" if $K_LOG end |
#set_ready! ⇒ Object
128 129 130 131 132 |
# File 'lib/kaya/suites/suite.rb', line 128 def set_ready! @status = "READY" $K_LOG.debug "[#{@id}:#{@name}] Marked as ready" if $K_LOG self.save! end |
#set_running! ⇒ Object
134 135 136 137 138 |
# File 'lib/kaya/suites/suite.rb', line 134 def set_running! @status= "RUNNING" $K_LOG.debug "[#{@id}:#{@name}] Marked as running" if $K_LOG self.save! end |
#suite_data_for(suite_name) ⇒ Object
72 73 74 |
# File 'lib/kaya/suites/suite.rb', line 72 def suite_data_for suite_name Kaya::Database::MongoConnector.suite_data_for(suite_name) end |
#suite_data_structure ⇒ Hash
Returns the structure of a suite data
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kaya/suites/suite.rb', line 78 def suite_data_structure { "_id" => id, "name" => name, "branch" => branch, "status" => status, "command" => command, "custom" => custom, "info" => info, "last_execution" => last_execution, "last_result" => last_result, "active" => active } end |