class CqlRuby::Executor

Attributes

collector[R]
filter_reader[R]
filters[R]
path[R]
pattern[R]
recursive[R]

Public Class Methods

new( collector:, filter_reader:, pattern:, path:, filters: [], recursive: true, include: nil, exclude: nil, search_type: :token ) click to toggle source
# File lib/cql_ruby/executor.rb, line 30
def initialize(
  collector:,
  filter_reader:,
  pattern:,
  path:,
  filters: [],
  recursive: true,
  include: nil,
  exclude: nil,
  search_type: :token
)
  @collector = collector
  @filter_reader = filter_reader
  @pattern = pattern
  @path = path
  @filters = filters
  @recursive = recursive
  @include = include
  @exclude = exclude
  @search_type = search_type
end

Public Instance Methods

search_all() click to toggle source
# File lib/cql_ruby/executor.rb, line 52
def search_all
  files.flat_map do |file|
    next if !@exclude.nil? && CqlRuby::PatternMatcher.match?(@exclude, file)
    next unless @include.nil? || CqlRuby::PatternMatcher.match?(@include, file)

    CqlRuby.log "File check: #{file}" if CqlRuby::Config.debug_level_3?
    search(file)
  end
end

Private Instance Methods

files() click to toggle source
# File lib/cql_ruby/executor.rb, line 99
def files
  return [path] if File.file?(path)

  clean_path = Pathname(path).cleanpath.to_s
  clean_path += '/**' if recursive
  clean_path += '/*.rb'

  Dir.glob(clean_path)
end
match?(target) click to toggle source
# File lib/cql_ruby/executor.rb, line 95
def match?(target)
  CqlRuby::PatternMatcher.match?(pattern, target)
end
search_for_node?() click to toggle source
# File lib/cql_ruby/executor.rb, line 113
def search_for_node?
  @search_type == :node
end
search_for_token?() click to toggle source
# File lib/cql_ruby/executor.rb, line 109
def search_for_token?
  @search_type == :token
end
walk(node, ancestors, source_reader) click to toggle source
# File lib/cql_ruby/executor.rb, line 75
def walk(node, ancestors, source_reader)
  if node.is_a?(Parser::AST::Node)
    if search_for_node?
      if match?(node.type) && CqlRuby::FilterEvaluator.pass?(filter_reader, ancestors, node)
        collector.add(CqlRuby::Crumb.new(node, ancestors, source_reader))
      end
    end

    node.children.flat_map do |child|
      walk(child, ancestors.dup + [node], source_reader)
    end
  else
    if search_for_token? && match?(node) && CqlRuby::FilterEvaluator.pass?(filter_reader, ancestors, node)
      collector.add(CqlRuby::Crumb.new(node, ancestors, source_reader))
    end
  end

  nil
end