Class: GitStore::User

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



2
3
4
# File 'lib/git_store/user.rb', line 2

def email
  @email
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/git_store/user.rb', line 2

def name
  @name
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



2
3
4
# File 'lib/git_store/user.rb', line 2

def time
  @time
end

Class Method Details

.config_get(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/git_store/user.rb', line 17

def self.config_get(key)
  value = `git config #{key}`.chomp

  if $?.exitstatus == 0
    return value unless value.empty?
    raise RuntimError, "#{key} is empty"
  else
    raise RuntimError, "No #{key} found in git config"
  end
end

.config_user_emailObject



28
29
30
# File 'lib/git_store/user.rb', line 28

def self.config_user_email
  email = `git config user.email`.chomp
end

.from_configObject



12
13
14
15
# File 'lib/git_store/user.rb', line 12

def self.from_config
  name, email = config_get('user.name'), config_get('user.email')
  new name, email, Time.now
end

.parse(user) ⇒ Object



32
33
34
35
36
# File 'lib/git_store/user.rb', line 32

def self.parse(user)
  if match = user.match(/(.*)<(.*)> (\d+) ([+-]\d+)/)
    new match[1].strip, match[2].strip, Time.at(match[3].to_i + match[4].to_i * 3600)
  end
end

Instance Method Details

#dumpObject Also known as: to_s



3
4
5
# File 'lib/git_store/user.rb', line 3

def dump
  "#{ name } <#{email}> #{ time.to_i } #{ time.strftime('%z') }"
end

#inspectObject



8
9
10
# File 'lib/git_store/user.rb', line 8

def inspect
  "#<GitStore::User name=%p email=%p time=%p>" % [name, email, time]
end