Class: GitPunch::User

Inherits:
Object
  • Object
show all
Defined in:
lib/git_punch/user.rb

Constant Summary collapse

EVERYTHING_BUT_THE_OWNER =
/(git|http|https):\/\/notepunch\.com(\:|\/)\.git/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 from_options={}
  from_options.each do |key,value|
    instance_variable_set "@#{key}", value
  end
end

Instance Attribute Details

#tokenObject (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_configObject



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_originObject



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

#credentialsObject



42
43
44
45
46
47
# File 'lib/git_punch/user.rb', line 42

def credentials
  {
    username: name,
    password: token
  }
end

#nameObject



14
15
16
# File 'lib/git_punch/user.rb', line 14

def name
  @name.strip
end

#present?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/git_punch/user.rb', line 18

def present?
  not name.empty?
end