Class: TTK::Testers::Tester::QueryNode

Inherits:
Node
  • Object
show all
Defined in:
lib/ttk/testers/tester/query_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, name, type, *sub_nodes) ⇒ QueryNode

Returns a new instance of QueryNode.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ttk/testers/tester/query_node.rb', line 18

def initialize(uri, name, type, *sub_nodes)
  super(nil, *sub_nodes)
  @uri = uri
  @tester_name = name
  @tester_type = type
  @query = nil
  @args = []
  @block = nil
  @result = nil
  @run = false
  @failed = false
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



31
32
33
# File 'lib/ttk/testers/tester/query_node.rb', line 31

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



31
32
33
# File 'lib/ttk/testers/tester/query_node.rb', line 31

def block
  @block
end

#queryObject (readonly)

Returns the value of attribute query.



31
32
33
# File 'lib/ttk/testers/tester/query_node.rb', line 31

def query
  @query
end

#resultObject (readonly)

Returns the value of attribute result.



31
32
33
# File 'lib/ttk/testers/tester/query_node.rb', line 31

def result
  @result
end

#uriObject (readonly)

Returns the value of attribute uri.



31
32
33
# File 'lib/ttk/testers/tester/query_node.rb', line 31

def uri
  @uri
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ttk/testers/tester/query_node.rb', line 49

def failed?
  @failed
end

#run(tester) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ttk/testers/tester/query_node.rb', line 33

def run(tester)
  begin
    if tester.requests.include?(@query)
      @run = true
      @result = tester.send(@query, *@args, &@block)
    end
  rescue Exception => exc
    @result = exc
    @failed = true
  end
end

#run?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ttk/testers/tester/query_node.rb', line 45

def run?
  @run
end

#set_query(query, *args, &block) ⇒ Object



53
54
55
56
57
# File 'lib/ttk/testers/tester/query_node.rb', line 53

def set_query(query, *args, &block)
  @query = query
  @args = args
  @block = block
end

#to_ttk_log(result, summary, min = 0, max = 0) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ttk/testers/tester/query_node.rb', line 59

def to_ttk_log(result, summary, min=0, max=0)
  desc = "#@tester_name [#@tester_type] {#{@uri.host}:#{@uri.port}}"
  result.new_node(desc) do
    if @run
      unless @failed or @result.nil?
        summary += @result[:summary]
        max += [@result[:test].weight, 0].max
        min += [@result[:test].weight, 0].min
        @result[:result].repeat(result)
      end
    end
    unless @sub_nodes.empty?
      result.new_node(:sub_results) do
        @sub_nodes.each do |sub_node|
          r = sub_node.to_ttk_log(result, summary, min, max)
          summary += r[0]
          min += r[1]
          max += r[2]
        end
      end
    end
  end
  [summary, min, max]
end