Module: Gauge::StaticLoader Private

Defined in:
lib/static_loader.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.aliases?(node) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


72
73
74
# File 'lib/static_loader.rb', line 72

def self.aliases?(node)
  return node.children[0].children.size > 3 && node.children[0].children[3].type == :str
end

.load_aliases(file, node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/static_loader.rb', line 76

def self.load_aliases(file, node)
  recoverable = false
  if recoverable? node
    aliases = node.children[0].children.slice(2, node.children[0].children.length() - 3)
    recoverable = true
  else
    aliases = node.children[0].children.slice(2, node.children[0].children.length() - 2)
  end
  Gauge::MethodCache.add_step_alias(*aliases.map {|x| x.children[0]})
  aliases.each {|x|
    sv = Gauge::Connector.step_value x.children[0]
    load_step(file, sv, x.children[0], node, {recoverable: recoverable})
  }
end

.load_files(dir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
# File 'lib/static_loader.rb', line 25

def self.load_files(dir)
  Dir["#{dir}/**/*.rb"].each do |x|
    load_steps(x, CodeParser.code_to_ast(File.read(x)))
  end
end

.load_step(file, step_value, step_text, block, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
100
101
# File 'lib/static_loader.rb', line 97

def self.load_step(file, step_value, step_text, block, options)
  si = {location: {file: file, span: block.loc}, step_text: step_text,
        block: block, recoverable: options[:recoverable]}
  Gauge::MethodCache.add_step(step_value, si)
end

.load_steps(file, ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
# File 'lib/static_loader.rb', line 42

def self.load_steps(file, ast)
  traverse ast do |node|
    process_node(file, node)
  end
end

.process_node(file, node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def self.process_node(file, node)
  if aliases?(node)
    load_aliases(file, node)
  else
    step_text = node.children[0].children[2].children[0]
    step_value = Gauge::Connector.step_value step_text
    load_step(file, step_value, step_text, node, {recoverable: recoverable?(node)})
  end
end

.recoverable?(node) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


91
92
93
94
95
# File 'lib/static_loader.rb', line 91

def self.recoverable?(node)
  size = node.children[0].children.length
  options = node.children[0].children[size - 1]
  options.type == :hash && options.children[0].children[0].children[0] == :continue_on_failure
end

.reload_steps(file, ast) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
# File 'lib/static_loader.rb', line 48

def self.reload_steps(file, ast)
  return unless ast
  remove_steps file
  load_steps(file, ast)
end

.remove_steps(file) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/static_loader.rb', line 54

def self.remove_steps(file)
  Gauge::MethodCache.remove_steps file
end

.step_node?(node) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


58
59
60
# File 'lib/static_loader.rb', line 58

def self.step_node?(node)
  node.type == :block && node.children[0].children[1] == :step
end

.traverse(ast, &visitor) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
36
37
38
39
40
# File 'lib/static_loader.rb', line 31

def self.traverse(ast, &visitor)
  return if ast.class != Parser::AST::Node
  if ast && step_node?(ast)
    visitor.call(ast)
  elsif ast&.children
    ast.children.each {|node|
      traverse(node, &visitor)
    }
  end
end