Module: Kaya::API::Suites

Defined in:
lib/kaya/API/suites.rb

Class Method Summary collapse

Class Method Details

.list(options = {}) ⇒ Object

Parameters:

  • options (hash) (defaults to: {})

    :active, :ip



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kaya/API/suites.rb', line 6

def self.list(options ={})

  start = Time.now.to_f

  response = {
    "project_name" => Dir.pwd.split("/").last,
    "size" => 0,
    "suites" => [],
    "message" => nil
  }
  suites = if options[:running]
    response["request"] = "Running Suites"
    Kaya::Suites.running_suites
  else
    response["request"] = options[:active] ? "Active Suites" : "Suites"
    Kaya::Suites.suites options[:active]
  end


  if suites.size.zero?
    response["message"] = options[:running] ? "Running suites not found" : "Suites not found"
  else
    # Gets the executions for given ip
    suites = suites.map do |suite|
      results_for_suite = Kaya::Results.results_ids_for suite["_id"]
      suite["results"]={
        "size" => results_for_suite.size,
        "ids" => results_for_suite
      }
      suite
    end

    suites = suites.map do |suite|
      unless Kaya::Results.results_for_suite_id_and_ip(suite["_id"], options[:ip]).empty?
        suite["status"]="RUNNING"
        suite
      else
        suite
      end
    end

    response["suites"] = suites
    $K_LOG.debug "#{suites.size} retrieved in (#{Time.now.to_f - start} s)" if $K_LOG

    response["size"] = suites.size
  end
  response
end