module MetaCommit::Extension::RubySupport::Helpers::ContextualAstAccessor

Public Instance Methods

contextual_ast_has_target_node(ast) click to toggle source
# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 75
def contextual_ast_has_target_node(ast)
  !ast.target_node.nil? && !ast.target_node.empty_ast?
end
is_in_context_of_class?(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast @return [Boolean]

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 59
def is_in_context_of_class?(ast)
  ast.context_nodes.each do |parent|
    return true if parent.is_class?
  end
  false
end
is_in_context_of_method?(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast @return [Boolean]

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 68
def is_in_context_of_method?(ast)
  ast.context_nodes.each do |parent|
    return true if parent.is_method?
  end
  false
end
is_in_context_of_module?(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast @return [Boolean]

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 50
def is_in_context_of_module?(ast)
  ast.context_nodes.each do |parent|
    return true if parent.is_module?
  end
  false
end
is_name_of_class?(ast) click to toggle source

on created class only first line goes to diff @param [MetaCommit::Model::ContextualAstNode] ast

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 17
def is_name_of_class?(ast)
  (ast.target_node.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].type == :class)
end
is_name_of_module?(ast) click to toggle source

on created module only first line goes to diff @param [MetaCommit::Model::ContextualAstNode] ast

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 23
def is_name_of_module?(ast)
  (ast.target_node.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].type == :module)
end
name_of_context_class(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 35
def name_of_context_class(ast)
  ast.context_nodes.reverse.each do |parent|
    return parent.class_name if parent.is_class?
  end
end
name_of_context_method(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 42
def name_of_context_method(ast)
  ast.context_nodes.reverse.each do |parent|
    return parent.method_name if parent.is_method?
  end
end
name_of_context_module(ast) click to toggle source

@param [MetaCommit::Model::ContextualAstNode] ast

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 28
def name_of_context_module(ast)
  ast.context_nodes.reverse.each do |parent|
    return parent.module_name if parent.is_module?
  end
end
path_to_component(ast, depth=nil) click to toggle source

@param [Object] ast @param [Integer] depth @return [String]

# File lib/meta_commit_ruby_support/helpers/contextual_ast_accessor.rb, line 6
def path_to_component(ast, depth=nil)
  depth = -1 if depth.nil?
  result = []
  result.concat([name_of_context_module(ast), is_in_context_of_class?(ast) && depth < 1 ? '::' : '']) if is_in_context_of_module?(ast) && depth < 2
  result.concat([name_of_context_class(ast)]) if is_in_context_of_class?(ast) && depth < 1
  result.concat(['#', name_of_context_method(ast)]) if is_in_context_of_method?(ast) && depth < 0
  result.join('')
end