Class: GitPunch::User
- Inherits:
-
Object
- Object
- GitPunch::User
- Defined in:
- lib/git_punch/user.rb
Constant Summary collapse
- EVERYTHING_BUT_THE_OWNER =
/(git|http|https):\/\/notepunch\.com(\:|\/)\.git/
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #credentials ⇒ Object
-
#initialize(from_options = {}) ⇒ User
constructor
A new instance of User.
- #name ⇒ Object
- #present? ⇒ Boolean
Constructor Details
#initialize(from_options = {}) ⇒ User
Returns a new instance of User.
8 9 10 11 12 |
# File 'lib/git_punch/user.rb', line 8 def initialize ={} .each do |key,value| instance_variable_set "@#{key}", value end end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/git_punch/user.rb', line 6 def token @token end |
Class Method Details
.from_config ⇒ Object
35 36 37 38 39 40 |
# File 'lib/git_punch/user.rb', line 35 def self.from_config username = `git config punch.username` api_key = `git config punch.token` new name: username, token: api_key end |
.from_origin ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git_punch/user.rb', line 22 def self.from_origin remote = `git remote show origin` raise "No origin configured" if remote.empty? line = remote.split("\n").select { |l| l =~ /Fetch URL/ }.first owner = if line =~ /\A(.*)\:(.*)\.git\Z/ $2.split('/')[-2] else "" end new name: owner end |
Instance Method Details
#credentials ⇒ Object
42 43 44 45 46 47 |
# File 'lib/git_punch/user.rb', line 42 def credentials { username: name, password: token } end |
#name ⇒ Object
14 15 16 |
# File 'lib/git_punch/user.rb', line 14 def name @name.strip end |
#present? ⇒ Boolean
18 19 20 |
# File 'lib/git_punch/user.rb', line 18 def present? not name.empty? end |