Class: Hiptest::NodeModifiers::ParameterTypeAdder

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameterTypeAdder

Returns a new instance of ParameterTypeAdder.



13
14
15
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 13

def initialize
  @call_types = CallTypes.new
end

Instance Attribute Details

#call_typesObject (readonly)

Returns the value of attribute call_types.



7
8
9
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 7

def call_types
  @call_types
end

Class Method Details

.add(project) ⇒ Object



9
10
11
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 9

def self.add(project)
  self.new.process(project)
end

Instance Method Details

#add_arguments_from(node, context = nil) ⇒ Object



66
67
68
69
70
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 66

def add_arguments_from(node, context = nil)
  node.each_sub_nodes(Hiptest::Nodes::Argument) do |argument|
    @call_types.add_argument_type(argument.children[:name], get_type(argument.children[:value], context))
  end
end

#gather_actionwords_default_parameters_types(project) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 40

def gather_actionwords_default_parameters_types(project)
  project.children[:actionwords].children[:actionwords].each do |actionword|
    @call_types.add_callable_item(actionword.children[:name], Hiptest::Nodes::Actionword)
    actionword.each_sub_nodes(Hiptest::Nodes::Parameter) do |parameter|
      default = parameter.children[:default]
      next if default.nil?
      @call_types.add_argument_type(parameter.children[:name], get_type(default))
    end
  end
end

#gather_call_argument_types(node) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 51

def gather_call_argument_types(node)
  node.each_sub_nodes(Hiptest::Nodes::Call) do |call|
    actionword_name = call.children[:actionword]

    @call_types.add_callable_item(actionword_name, Hiptest::Nodes::Actionword)
    add_arguments_from(call, node)
  end
end

#gather_scenarios_argument_types(project) ⇒ Object



33
34
35
36
37
38
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 33

def gather_scenarios_argument_types(project)
  project.children[:scenarios].children[:scenarios].each do |scenario|
    @call_types.add_callable_item(scenario.children[:name], Hiptest::Nodes::Scenario)
    add_arguments_from(scenario.children[:datatable])
  end
end

#process(project) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 17

def process(project)
  gather_scenarios_argument_types(project)
  gather_actionwords_default_parameters_types(project)

  # To have the most accurate type, the closest calls must be computed
  # first, and deepest calls must be computed last (because they  depend
  # on previous calls types).
  distances_index = Hiptest::ProjectGrapher.distances_index(project)
  distances_index.each_value do |items|  # distances_index items are sorted by distance, from closest to deepest
    items.each do |item|
      write_parameter_types_to_item(item)
      gather_call_argument_types(item)
    end
  end
end

#write_parameter_types_to_item(callable_item) ⇒ Object



60
61
62
63
64
# File 'lib/hiptest-publisher/node_modifiers/parameter_type_adder.rb', line 60

def write_parameter_types_to_item(callable_item)
  callable_item.each_sub_nodes(Hiptest::Nodes::Parameter) do |parameter|
    parameter.children[:type] = @call_types.type_of(callable_item.children[:name], parameter.children[:name], callable_item.class)
  end
end