class Yoda::Parsing::Query::CurrentLocationQuery

Attributes

ast[R]
location[R]

Public Class Methods

new(ast, location) click to toggle source

@param ast [::Parser::AST::Node] @param location [Location]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 9
def initialize(ast, location)
  @ast = ast
  @location = location
end

Public Instance Methods

current_method_definition() click to toggle source

@return [NodeObjects::MethodDefition, nil]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 20
def current_method_definition
  @current_method_definition ||= namespace.calc_current_location_method(location)
end
current_namespace() click to toggle source

@return [NodeObjects::Namespace, nil]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 15
def current_namespace
  @current_namespace ||= namespace.calc_current_location_namespace(location)
end

Private Instance Methods

calc_nodes_to_current_location(root_node, current_location) click to toggle source

@param root_node [Array<::Parser::AST::Node>] @param current_location [Parser::Source::Map] @return [Array<::Parser::AST::Node>]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 39
def calc_nodes_to_current_location(root_node, current_location)
  nodes = []
  node = root_node
  while node && !node.children.empty?
    nodes << node
    node = node.children.find { |n| n.respond_to?(:location) && current_location.included?(n.location) }
  end
  nodes
end
namespace() click to toggle source

@return [Namespace]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 27
def namespace
  @namespace ||= NodeObjects::Namespace.new(self.ast)
end
nodes_to_current_location_from_root() click to toggle source

@return [Array<::Parser::AST::Node>]

# File lib/yoda/parsing/query/current_location_node_query.rb, line 32
def nodes_to_current_location_from_root
  @nodes_to_current_location ||= calc_nodes_to_current_location(ast, location)
end