Class: PageObjectStubs::ProcessPageObjects

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/page_object_stubs/ast_processor.rb

Constant Summary collapse

@@valid_elements =

page-object/lib/page-object/elements/*.rb plus page_url

%w[area audio button canvas check_box div element file_field form heading hidden_field image
label link list_item media option ordered_list paragraph radio_button select_list span table
table_cell table_row text_area text_field unordered_list video] + %w[page_url]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessPageObjects

Returns a new instance of ProcessPageObjects.



6
7
8
9
# File 'lib/page_object_stubs/ast_processor.rb', line 6

def initialize
  @name_type_pairs = []
  super
end

Instance Attribute Details

#name_type_pairsObject (readonly)

Returns the value of attribute name_type_pairs.



4
5
6
# File 'lib/page_object_stubs/ast_processor.rb', line 4

def name_type_pairs
  @name_type_pairs
end

Instance Method Details

#_print_children(children_array) ⇒ Object



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
# File 'lib/page_object_stubs/ast_processor.rb', line 21

def _print_children children_array
  # `def on_send` receives AST::Node send
  # the children array of that node is sent to _print_children
  # -> symbol :page_url
  # inside print children, the element type is found (page_url)
  # -> AST::Node str/symbol
  # once we know the type, we look for an AST::Node that contains the element name

  pair = []

  find_element_name = false
  element_name      = nil # symbol or string
  children_array.each do |child|
    if find_element_name && child.is_a?(AST::Node)
      first = child.children.first
      if first.class == Symbol || first.class == String
        element_name = first.to_s
        # puts "element_name: #{element_name}"
        pair << element_name
        break
      end
    end

    if is_valid child
      # puts "element_type: #{child}"
      pair << child.to_s # element_type
      find_element_name = true
    end unless find_element_name
  end

  @name_type_pairs << pair if pair.length == 2
end

#generate_send(node) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/page_object_stubs/ast_processor.rb', line 54

def generate_send node
  c = node.children

  return unless c
  _print_children c
  # node.type is send
  # the rest of the data is in the children.
end

#is_valid(child) ⇒ Object



16
17
18
19
# File 'lib/page_object_stubs/ast_processor.rb', line 16

def is_valid child
  # child may be a symbol or a string
  @@valid_elements.include?(child.to_s)
end

#on_def(node) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/page_object_stubs/ast_processor.rb', line 63

def on_def node
  if node.is_a?(AST::Node)
    c = node.children
    return unless c
    method_name = c.first
    @name_type_pairs << [method_name] if method_name.class == Symbol
  end
end

#on_send(node) ⇒ Object



72
73
74
75
# File 'lib/page_object_stubs/ast_processor.rb', line 72

def on_send node
  generate_send node
  super
end