Module: Gas

Defined in:
lib/gas.rb,
lib/gas/user.rb,
lib/gas/config.rb,
lib/gas/version.rb,
lib/gas/gitconfig.rb

Defined Under Namespace

Classes: Config, Gitconfig, User

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.add(nickname, name, email) ⇒ Object

Adds a author to the config

Parameters:

  • nickname (String)

    The nickname of the author

  • name (String)

    The name of the author

  • email (String)

    The email of the author



42
43
44
45
46
47
48
49
50
# File 'lib/gas.rb', line 42

def self.add(nickname, name, email)
  self.has_user? nickname
  user = User.new name, email, nickname
  @config.add user
  @config.save!

  puts 'Added author'
  puts user
end

.delete(nickname) ⇒ Object

Deletes a author from the config using nickname

Parameters:

  • nickname (String)

    The nickname of the author



54
55
56
57
58
59
60
# File 'lib/gas.rb', line 54

def self.delete(nickname)
  self.no_user? nickname
  @config.delete nickname
  @config.save!

  puts "Deleted author #{nickname}"
end

.has_user?(nickname) ⇒ Boolean

Checks if the user exists and gives error and exit if so

Parameters:

  • nickname (String)

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/gas.rb', line 78

def self.has_user?(nickname)
  if @config.exists? nickname
    puts "Nickname #{nickname} does already exist"
    exit
  end
end

.listObject

Lists all authors



12
13
14
15
16
17
# File 'lib/gas.rb', line 12

def self.list
  puts 'Available users:'
  puts @config

  self.show
end

.no_user?(nickname) ⇒ Boolean

Checks if the user exists and gives error and exit if not

Parameters:

  • nickname (String)

Returns:

  • (Boolean)


69
70
71
72
73
74
# File 'lib/gas.rb', line 69

def self.no_user?(nickname)
  if !@config.exists? nickname
    puts "Nickname #{nickname} does not exist"
    exit
  end
end

.showObject

Shows the current user



20
21
22
23
24
# File 'lib/gas.rb', line 20

def self.show
  user = @gitconfig.current_user
  puts 'Current user:'
  puts "#{user.name} <#{user.email}>"
end

.use(nickname) ⇒ Object

Sets nickname as current user

Parameters:

  • nickname (String)

    The nickname to use



28
29
30
31
32
33
34
35
36
# File 'lib/gas.rb', line 28

def self.use(nickname)
  self.no_user? nickname
  user = @config[nickname]

  @gitconfig.change_user user.name, user.email
  @gitconfig.save!

  self.show
end

.versionObject

Prints the current version



63
64
65
# File 'lib/gas.rb', line 63

def self.version
  puts Gas::VERSION
end