module Gauge::StaticLoader
@api private
Public Class Methods
Source
# File lib/static_loader.rb, line 60 def self.aliases?(node) return node.children[0].children.size > 3 && node.children[0].children[3].type == :str end
Source
# File lib/static_loader.rb, line 64 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::Util.step_value x.children[0] load_step(file, sv, x.children[0], node, {recoverable: recoverable}) } end
Source
# File lib/static_loader.rb, line 13 def self.load_files(dir) Dir["#{dir}/**/*.rb"].each do |x| load_steps(x, CodeParser.code_to_ast(File.read(x))) end end
Source
# File lib/static_loader.rb, line 85 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
Source
# File lib/static_loader.rb, line 30 def self.load_steps(file, ast) traverse ast do |node| process_node(file, node) end end
Source
# File lib/static_loader.rb, line 50 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::Util.step_value step_text load_step(file, step_value, step_text, node, {recoverable: recoverable?(node)}) end end
Source
# File lib/static_loader.rb, line 79 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
Source
# File lib/static_loader.rb, line 36 def self.reload_steps(file, ast) return unless ast remove_steps file load_steps(file, ast) end
Source
# File lib/static_loader.rb, line 42 def self.remove_steps(file) Gauge::MethodCache.remove_steps file end
Source
# File lib/static_loader.rb, line 46 def self.step_node?(node) node.type == :block && node.children[0].children[1] == :step end
Source
# File lib/static_loader.rb, line 19 def self.traverse(ast, &visitor) return if !ast || ast.class != Parser::AST::Node if step_node?(ast) visitor.call(ast) elsif ast.children ast.children.each {|node| traverse(node, &visitor) } end end