class Fast::Node

Set some convention methods from file.

This is not required by default, so to use it, you should require it first.

@example
  require 'fast/git'
  Fast.ast_from_file('lib/fast.rb').git_log.first.author.name # => "Jonatas Davi Paganini"

Public Instance Methods

author() click to toggle source

@return [String] with the first element from blame_authors

# File lib/fast.rb, line 100
def author
  blame_authors.first
end
blame_authors() click to toggle source

@return [Array<String>] with authors from the current expression range

# File lib/fast.rb, line 93
def blame_authors
  `git blame -L #{expression.first_line},#{expression.last_line} #{buffer_name}`.lines.map do |line|
    line.split('(')[1].split(/\d+/).first.strip
  end
end
buffer_name() click to toggle source

@return [String] with path of the file or simply buffer name.

# File lib/fast.rb, line 73
def buffer_name
  expression.source_buffer.name
end
capture(pattern, *args) click to toggle source

Captures elements from search recursively @param [String] pattern @param [Array] *args extra arguments to interpolate in the pattern. @return [Array<Fast::Node>>] with files and results

# File lib/fast.rb, line 116
def capture(pattern, *args)
  Fast.capture(pattern, self, *args)
end
expression() click to toggle source

@return [Parser::Source::Range] from the expression

# File lib/fast.rb, line 78
def expression
  location.expression
end
file() click to toggle source
# File lib/fast/git.rb, line 58
def file
  buffer_name.gsub("#{Dir.pwd}/", '')
end
from_file?() click to toggle source

@return [Boolean] true if a file exists with the buffer_name

# File lib/fast.rb, line 88
def from_file?
  File.exist?(buffer_name)
end
git() click to toggle source

@return [Git::Base] from current directory

# File lib/fast/git.rb, line 13
def git
  require 'git' unless defined? Git
  Git.open('.')
end
git_blob() click to toggle source

@return [Git::Object::Blob] from current buffer_name

# File lib/fast/git.rb, line 19
def git_blob
  return unless from_file?

  git.gblob(buffer_name)
end
git_log() click to toggle source

@return [Git::Log] from the current git_blob

buffer-name
# File lib/fast/git.rb, line 27
def git_log
  git_blob.log
end
last_commit() click to toggle source

@return [Git::Object::Commit]

# File lib/fast/git.rb, line 32
def last_commit
  git_log.first
end
line_range() click to toggle source

@return

# File lib/fast/git.rb, line 63
def line_range
  lines.map { |l| "L#{l}" }.join('-')
end
lines() click to toggle source

@return [Array] with lines range

# File lib/fast/git.rb, line 68
def lines
  exp = loc.expression
  first_line = exp.first_line
  last_line = exp.last_line
  [first_line, last_line].uniq
end
lines_of_code() click to toggle source

@return [Integer] lines of code from current block

# File lib/fast/git.rb, line 76
def lines_of_code
  lines.last - lines.first + 1
end
project_url() click to toggle source

Given remote_url is “git@github.com:namespace/project.git” Or remote_url is “github.com/namespace/project.git” @return [String] “github.com/namespace/project

# File lib/fast/git.rb, line 49
def project_url
  return remote_url.gsub(/\.git$/, '') if remote_url.start_with?('https')

  remote_url
    .gsub('git@', 'https://')
    .gsub(/:(\w)/, '/\\1')
    .gsub(/\.git$/, '')
end
remote_url() click to toggle source

@return [String] with remote URL

# File lib/fast/git.rb, line 42
def remote_url
  git.remote.url
end
sha() click to toggle source

@return [String] with last commit SHA

# File lib/fast/git.rb, line 37
def sha
  last_commit.sha
end
source() click to toggle source

@return [String] with the content of the expression

# File lib/fast.rb, line 83
def source
  expression.source
end