Class: Fast::Node
- Inherits:
-
Astrolabe::Node
- Object
- Astrolabe::Node
- Fast::Node
- Defined in:
- lib/fast.rb,
lib/fast/git.rb
Overview
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..name # => "Jonatas Davi Paganini"
Direct Known Subclasses
Instance Method Summary collapse
-
#author ⇒ String
With the first element from #blame_authors.
-
#blame_authors ⇒ Array<String>
With authors from the current expression range.
-
#buffer_name ⇒ String
With path of the file or simply buffer name.
-
#capture(pattern, *args) ⇒ Array<Fast::Node>
Captures elements from search recursively.
-
#expression ⇒ Parser::Source::Range
From the expression.
- #file ⇒ Object
-
#from_file? ⇒ Boolean
True if a file exists with the #buffer_name.
-
#git ⇒ Git::Base
From current directory.
-
#git_blob ⇒ Git::Object::Blob
From current #buffer_name.
-
#git_log ⇒ Git::Log
From the current #git_blob buffer-name.
- #last_commit ⇒ Git::Object::Commit
- #line_range ⇒ Object
-
#lines ⇒ Array
With lines range.
-
#lines_of_code ⇒ Integer
Lines of code from current block.
-
#link ⇒ String
With formatted repositorym link.
-
#md_link(text = md_link_description) ⇒ String
A markdown link with #md_link_description and #link.
-
#md_link_description ⇒ String
able to create a markdown link without parens.
-
#permalink ⇒ String
With permanent link to the actual commit.
-
#project_url ⇒ String
Given #remote_url is “[email protected]:namespace/project.git” Or #remote_url is “github.com/namespace/project.git”.
-
#remote_url ⇒ String
With remote URL.
-
#search(pattern, *args) ⇒ Array<Fast::Node>
Search recursively into a node and its children using a pattern.
-
#sha ⇒ String
With last commit SHA.
-
#source ⇒ String
With the content of the #expression.
Instance Method Details
#author ⇒ String
Returns with the first element from #blame_authors.
100 101 102 |
# File 'lib/fast.rb', line 100 def .first end |
#blame_authors ⇒ Array<String>
Returns with authors from the current expression range.
93 94 95 96 97 |
# File 'lib/fast.rb', line 93 def `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 ⇒ String
Returns with path of the file or simply buffer name.
73 74 75 |
# File 'lib/fast.rb', line 73 def buffer_name expression.source_buffer.name end |
#capture(pattern, *args) ⇒ Array<Fast::Node>
Captures elements from search recursively
116 117 118 |
# File 'lib/fast.rb', line 116 def capture(pattern, *args) Fast.capture(pattern, self, *args) end |
#expression ⇒ Parser::Source::Range
Returns from the expression.
78 79 80 |
# File 'lib/fast.rb', line 78 def expression location.expression end |
#file ⇒ Object
58 59 60 |
# File 'lib/fast/git.rb', line 58 def file buffer_name.gsub("#{Dir.pwd}/", '') end |
#from_file? ⇒ Boolean
Returns true if a file exists with the #buffer_name.
88 89 90 |
# File 'lib/fast.rb', line 88 def from_file? File.exist?(buffer_name) end |
#git ⇒ Git::Base
Returns from current directory.
13 14 15 16 |
# File 'lib/fast/git.rb', line 13 def git require 'git' unless defined? Git Git.open('.') end |
#git_blob ⇒ Git::Object::Blob
Returns from current #buffer_name.
19 20 21 22 23 |
# File 'lib/fast/git.rb', line 19 def git_blob return unless from_file? git.gblob(buffer_name) end |
#git_log ⇒ Git::Log
Returns from the current #git_blob buffer-name.
27 28 29 |
# File 'lib/fast/git.rb', line 27 def git_log git_blob.log end |
#last_commit ⇒ Git::Object::Commit
32 33 34 |
# File 'lib/fast/git.rb', line 32 def last_commit git_log.first end |
#line_range ⇒ Object
63 64 65 |
# File 'lib/fast/git.rb', line 63 def line_range lines.map { |l| "L#{l}" }.join('-') end |
#lines ⇒ Array
Returns with lines range.
68 69 70 71 72 73 |
# 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 ⇒ Integer
Returns lines of code from current block.
76 77 78 |
# File 'lib/fast/git.rb', line 76 def lines_of_code lines.last - lines.first + 1 end |
#link ⇒ String
Returns with formatted repositorym link.
92 93 94 |
# File 'lib/fast/git.rb', line 92 def link "#{project_url}/blob/master/#{buffer_name}##{line_range}" end |
#md_link(text = md_link_description) ⇒ String
Returns a markdown link with #md_link_description and #link.
81 82 83 |
# File 'lib/fast/git.rb', line 81 def md_link(text = md_link_description) "[#{text}](#{link})" end |
#md_link_description ⇒ String
able to create a markdown link without parens.
87 88 89 |
# File 'lib/fast/git.rb', line 87 def md_link_description source[/([^\r\(]+)\(/, 1] || source end |
#permalink ⇒ String
Returns with permanent link to the actual commit.
97 98 99 |
# File 'lib/fast/git.rb', line 97 def permalink "#{project_url}/blob/#{sha}/#{buffer_name}##{line_range}" end |
#project_url ⇒ String
Given #remote_url is “[email protected]:namespace/project.git” Or #remote_url is “github.com/namespace/project.git”
49 50 51 52 53 54 55 56 |
# 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 ⇒ String
Returns with remote URL.
42 43 44 |
# File 'lib/fast/git.rb', line 42 def remote_url git.remote.url end |
#search(pattern, *args) ⇒ Array<Fast::Node>
Search recursively into a node and its children using a pattern.
108 109 110 |
# File 'lib/fast.rb', line 108 def search(pattern, *args) Fast.search(pattern, self, *args) end |
#sha ⇒ String
Returns with last commit SHA.
37 38 39 |
# File 'lib/fast/git.rb', line 37 def sha last_commit.sha end |
#source ⇒ String
Returns with the content of the #expression.
83 84 85 |
# File 'lib/fast.rb', line 83 def source expression.source end |