Module: Gas
- Defined in:
- lib/gas.rb,
lib/gas/user.rb,
lib/gas/users.rb,
lib/gas/version.rb,
lib/gas/git_config.rb
Defined Under Namespace
Modules: GitConfig Classes: User, Users
Constant Summary collapse
- VERSION =
'1.0.3'
Class Method Summary collapse
-
.add(nickname, name, email) ⇒ Object
Adds a author to the config.
-
.check_if_user_already_exists(nickname) ⇒ Object
Checks if the user exists and gives error and exit if so.
-
.check_if_user_does_not_exist(nickname) ⇒ Object
Checks if the user exists and gives error and exit if not.
-
.check_parameters(number_of_parameters_required, message) ⇒ Object
Checks the number of parameters and exits with a message if wrong number of parameters is supplied.
-
.delete(nickname) ⇒ Object
Deletes an author from the config using nickname.
-
.import(nickname) ⇒ Object
Imports current user from .gitconfig to .gas.
-
.list ⇒ Object
Lists all authors.
-
.print_usage ⇒ Object
Print usage information to stdout.
-
.print_version ⇒ Object
Print version information to stdout.
-
.show ⇒ Object
Shows the current user.
-
.use(nickname) ⇒ Object
Sets nickname as current user.
-
.users ⇒ Gas::Users
Returns the users object so we don’t use it directly.
Class Method Details
.add(nickname, name, email) ⇒ Object
Adds a author to the config
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gas.rb', line 87 def self.add(nickname, name, email) check_if_user_already_exists(nickname) user = User.new name, email, nickname users.add user users.save! puts 'Added new author' puts user end |
.check_if_user_already_exists(nickname) ⇒ Object
Checks if the user exists and gives error and exit if so
45 46 47 48 49 50 |
# File 'lib/gas.rb', line 45 def self.check_if_user_already_exists(nickname) if users.exists? nickname puts "Nickname #{nickname} already exists" exit end end |
.check_if_user_does_not_exist(nickname) ⇒ Object
Checks if the user exists and gives error and exit if not
36 37 38 39 40 41 |
# File 'lib/gas.rb', line 36 def self.check_if_user_does_not_exist(nickname) if !users.exists? nickname puts "Nickname #{nickname} does not exist" exit end end |
.check_parameters(number_of_parameters_required, message) ⇒ Object
Checks the number of parameters and exits with a message if wrong number of parameters is supplied
27 28 29 30 31 32 |
# File 'lib/gas.rb', line 27 def self.check_parameters(number_of_parameters_required, ) unless ARGV.length == number_of_parameters_required puts exit end end |
.delete(nickname) ⇒ Object
Deletes an author from the config using nickname
120 121 122 123 124 125 126 127 128 |
# File 'lib/gas.rb', line 120 def self.delete(nickname) check_if_user_does_not_exist(nickname) users.delete nickname users.save! puts "Deleted author #{nickname}" return true end |
.import(nickname) ⇒ Object
Imports current user from .gitconfig to .gas
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gas.rb', line 100 def self.import(nickname) check_if_user_already_exists(nickname) user = GitConfig.current_user if user user = User.new user.name, user.email, nickname users.add user users.save! puts 'Imported author' puts user else puts 'No current user to import' end end |
.list ⇒ Object
Lists all authors
53 54 55 56 57 58 59 |
# File 'lib/gas.rb', line 53 def self.list puts puts 'Available users:' puts puts users puts end |
.print_usage ⇒ Object
Print usage information to stdout
20 21 22 |
# File 'lib/gas.rb', line 20 def self.print_usage puts "Usage: command [parameters]\n\nBuilt-in commands:\n add NICKNAME NAME EMAIL - adds a new user to gas\n delete NICKNAME - deletes a user from gas\n import NICKNAME - imports the user from .gitconfig into NICKNAME\n list - lists all users\n plugins - lists all installed plugins\n show - shows the current user\n use NICKNAME - sets the user with NICKNAME as the current user" end |
.print_version ⇒ Object
Print version information to stdout
15 16 17 |
# File 'lib/gas.rb', line 15 def self.print_version puts Gas::VERSION end |
.show ⇒ Object
Shows the current user
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gas.rb', line 62 def self.show user = GitConfig.current_user if user puts 'Current user:' puts "#{user.name} <#{user.email}>" else puts 'No current user in gitconfig' end end |
.use(nickname) ⇒ Object
Sets nickname as current user
75 76 77 78 79 80 81 |
# File 'lib/gas.rb', line 75 def self.use(nickname) check_if_user_does_not_exist(nickname) user = users.get nickname GitConfig.change_user user self.show end |
.users ⇒ Gas::Users
Returns the users object so we don’t use it directly
132 133 134 |
# File 'lib/gas.rb', line 132 def self.users @users end |