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
@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
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
@return [Parser::Source::Range] from the expression
# File lib/fast.rb, line 78 def expression location.expression end
# File lib/fast/git.rb, line 58 def file buffer_name.gsub("#{Dir.pwd}/", '') end
@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
@return [Git::Base] from current directory
# File lib/fast/git.rb, line 13 def git require 'git' unless defined? Git Git.open('.') end
@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
@return [Git::Log] from the current git_blob
buffer-name
# File lib/fast/git.rb, line 27 def git_log git_blob.log end
@return [Git::Object::Commit]
# File lib/fast/git.rb, line 32 def last_commit git_log.first end
@return
# File lib/fast/git.rb, line 63 def line_range lines.map { |l| "L#{l}" }.join('-') end
@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
@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
@return [String] with formatted repositorym link
# File lib/fast/git.rb, line 92 def link "#{project_url}/blob/master/#{buffer_name}##{line_range}" end
@return [String] a markdown link with md_link_description
and link
# File lib/fast/git.rb, line 81 def md_link(text = md_link_description) "[#{text}](#{link})" end
@return [String] with the source cutting arguments from method calls to be able to create a markdown link without parens.
# File lib/fast/git.rb, line 87 def md_link_description source[/([^\r\(]+)\(/, 1] || source end
@return [String] with permanent link to the actual commit
# File lib/fast/git.rb, line 97 def permalink "#{project_url}/blob/#{sha}/#{buffer_name}##{line_range}" end
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
@return [String] with remote URL
# File lib/fast/git.rb, line 42 def remote_url git.remote.url end
Search recursively into a node and its children using a pattern. @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 108 def search(pattern, *args) Fast.search(pattern, self, *args) end
@return [String] with last commit SHA
# File lib/fast/git.rb, line 37 def sha last_commit.sha end
@return [String] with the content of the expression
# File lib/fast.rb, line 83 def source expression.source end