Class: Peek::Views::Git
- Inherits:
-
View
- Object
- View
- Peek::Views::Git
- Defined in:
- lib/peek/views/git.rb
Instance Method Summary collapse
-
#branch_name ⇒ Object
Fetch the current branch name.
- #compare_url ⇒ Object
-
#initialize(options = {}) ⇒ Git
constructor
A view to get some insight into the current state of git for your project.
- #nwo? ⇒ Boolean
-
#sha ⇒ Object
Fetch the current sha if one isn’t present.
- #short_sha ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Git
A view to get some insight into the current state of git for your project. It gives you the sha, branch, and compare url.
nwo - The repository (name with owner). default_branch - master may not be your default branch. branch_name - The current branch name (Optional). sha - The current SHA for git (Optional). domain - Domain name of the location of the repository (Default: github.com). protocol - The protocol to use in the compare_url (Default: https).
Returns Peek::Views::Git
16 17 18 19 20 21 22 23 |
# File 'lib/peek/views/git.rb', line 16 def initialize( = {}) @nwo = .delete(:nwo) @default_branch = .fetch(:default_branch, 'master') @branch_name = .delete(:branch_name) @sha = .delete(:sha) @domain = .fetch(:domain, 'github.com') @protocol = .fetch(:protocol, 'https') end |
Instance Method Details
#branch_name ⇒ Object
Fetch the current branch name.
30 31 32 |
# File 'lib/peek/views/git.rb', line 30 def branch_name @branch_name ||= ENV['GIT_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.chomp end |
#compare_url ⇒ Object
43 44 45 |
# File 'lib/peek/views/git.rb', line 43 def compare_url "#{@protocol}://#{@domain}/#{@nwo}/compare/#{@default_branch}...#{sha}" end |
#nwo? ⇒ Boolean
25 26 27 |
# File 'lib/peek/views/git.rb', line 25 def nwo? !!@nwo end |
#sha ⇒ Object
Fetch the current sha if one isn’t present.
35 36 37 |
# File 'lib/peek/views/git.rb', line 35 def sha @sha ||= ENV['GIT_SHA'] || `git rev-parse HEAD`.chomp end |
#short_sha ⇒ Object
39 40 41 |
# File 'lib/peek/views/git.rb', line 39 def short_sha sha[0..6] end |