class MetaCommit::Extension::RubySupport::Models::Ast

Adapter which implements MetaCommit::Contracts::Ast contract and wraps Parser::AST::Node @attr [Array<Parser::AST::Node>] ast

Attributes

ast[R]

Public Class Methods

new(ast) click to toggle source

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

# File lib/meta_commit_ruby_support/models/ast.rb, line 8
def initialize(ast)
  @ast = ast
end

Public Instance Methods

children() click to toggle source

@return [Array<MetaCommit::Contracts::Ast>]

# File lib/meta_commit_ruby_support/models/ast.rb, line 13
def children
  begin
    @ast.children
        .map {|child| Ast.new(child)}
  rescue NoMethodError
    return []
  end
end
class_name() click to toggle source

@return [String]

# File lib/meta_commit_ruby_support/models/ast.rb, line 74
def class_name
  @ast.children.first.children.last.to_s
end
classes() click to toggle source

@return [Array<Ast>]

# File lib/meta_commit_ruby_support/models/ast.rb, line 84
def classes
  accumulator=[]
  begin
    return if empty_ast?
    return self if is_class?
    accumulator.concat(children.map {|child| child.classes})
  rescue NoMethodError
    return nil
  end
  accumulator.flatten.compact
end
empty_ast?() click to toggle source

@return [Boolean]

# File lib/meta_commit_ruby_support/models/ast.rb, line 43
def empty_ast?
  @ast.nil?
end
first_line() click to toggle source

@return [Integer]

# File lib/meta_commit_ruby_support/models/ast.rb, line 23
def first_line
  return unless @ast.respond_to?(:location)
  begin
    return @ast.location.first_line
  rescue NoMethodError
    return nil
  end
end
is_class?() click to toggle source

@return [Boolean]

# File lib/meta_commit_ruby_support/models/ast.rb, line 53
def is_class?
  type == :class
end
is_method?() click to toggle source

@return [Boolean]

# File lib/meta_commit_ruby_support/models/ast.rb, line 58
def is_method?
  type == :def
end
is_module?() click to toggle source

@return [Boolean]

# File lib/meta_commit_ruby_support/models/ast.rb, line 48
def is_module?
  type == :module
end
last_line() click to toggle source

@return [Integer]

# File lib/meta_commit_ruby_support/models/ast.rb, line 33
def last_line
  return unless @ast.respond_to?(:location)
  begin
    return @ast.location.last_line
  rescue NoMethodError
    return nil
  end
end
method_name() click to toggle source

@return [String]

# File lib/meta_commit_ruby_support/models/ast.rb, line 79
def method_name
  @ast.children.first.to_s
end
module_name() click to toggle source

@return [String]

# File lib/meta_commit_ruby_support/models/ast.rb, line 69
def module_name
  @ast.children.first.children.last.to_s
end
to_s() click to toggle source
# File lib/meta_commit_ruby_support/models/ast.rb, line 96
def to_s
  @ast.to_s
end
type() click to toggle source

@return [Symbol]

# File lib/meta_commit_ruby_support/models/ast.rb, line 63
def type
  return @ast.class.to_s.to_sym unless @ast.respond_to?(:type)
  @ast.type
end