class RubyDetective::AST::Nodes::Query

Attributes

node[R]

Public Class Methods

new(node) click to toggle source
# File lib/ruby_detective/ast/nodes/query.rb, line 7
def initialize(node)
  @node = node
end

Public Instance Methods

class_declarations() click to toggle source
# File lib/ruby_detective/ast/nodes/query.rb, line 50
def class_declarations
  deep_search(node, [:class_declaration_node?])
end
constant_references(where: {}) click to toggle source

TODO: ignore constant definitions, only return constant references

# File lib/ruby_detective/ast/nodes/query.rb, line 23
def constant_references(where: {})
  constants = deep_search(node, [:constant_reference_node?])

  case
  when where.key?(:namespace)
    constants.select { |c| c.namespace.include?(where[:namespace].to_sym) }
  else
    constants
  end
end
top_level_constant_references(where: {}) click to toggle source

TODO: ignore constant definitions, only return constant references This finds all constants, ignoring the nested ones. For example: The “Foo::Bar” code contain two constants, but this method will only bring up one (the Bar one), with access to it's full path.

# File lib/ruby_detective/ast/nodes/query.rb, line 39
def top_level_constant_references(where: {})
  constants = deep_search(node, [:constant_reference_node?, :top_level_constant?])

  case
  when where.key?(:namespace)
    constants.select { |c| c.namespace.include?(where[:namespace].to_sym) }
  else
    constants
  end
end
where(criteria = {}) click to toggle source

TODO: accept multiple criteria

# File lib/ruby_detective/ast/nodes/query.rb, line 12
def where(criteria = {})
  case
  when criteria.key?(:type)
    type_validation_function = ->(node) { node.type == criteria[:type] }
    deep_search(node, [type_validation_function])
  else
    deep_search(node)
  end
end

Private Instance Methods