Module: Gas
- Defined in:
- lib/gas.rb,
lib/gas/ssh.rb,
lib/gas/user.rb,
lib/gas/config.rb,
lib/gas/version.rb,
lib/gas/prompter.rb,
lib/gas/settings.rb,
lib/gas/gitconfig.rb,
lib/gas/github_speaker.rb
Defined Under Namespace
Modules: Prompter Classes: Config, Gitconfig, GithubSpeaker, Settings, Ssh, User
Constant Summary collapse
- VERSION =
'0.1.8'
Class Method Summary collapse
-
.add(nickname, name, email, github_speaker = nil) ⇒ Object
Adds a author to the config.
-
.delete(nickname) ⇒ Object
Deletes an author from the config using nickname.
-
.has_user?(nickname) ⇒ Boolean
Checks if the user exists and gives error and exit if so.
-
.import(nickname) ⇒ Object
Imports current user from .gitconfig to .gas.
-
.list ⇒ Object
Lists all authors.
-
.no_user?(nickname) ⇒ Boolean
Checks if the user exists and gives error and exit if not.
-
.show ⇒ Object
Shows the current user.
-
.ssh(nickname) ⇒ Object
Adds an ssh key for the specified user.
-
.use(nickname) ⇒ Object
Sets nickname as current user.
-
.version ⇒ Object
Prints the current version.
Class Method Details
.add(nickname, name, email, github_speaker = nil) ⇒ Object
Adds a author to the config
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gas.rb', line 62 def self.add(nickname, name, email, github_speaker = nil) return false if self.has_user?(nickname) user = User.new name, email, nickname @config.add user @config.save! using_ssh = Ssh.setup_ssh_keys user Ssh.upload_public_key_to_github(user, github_speaker) if using_ssh puts 'Added new author' puts user end |
.delete(nickname) ⇒ Object
Deletes an author from the config using nickname
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/gas.rb', line 133 def self.delete(nickname) return false unless self.no_user? nickname # I re-engineered this section so I could use Gas.delete in a test even when that author didn't exist # TODO: The name no_user? is now very confusing. It should be changed to something like "user_exists?" now maybe? Ssh.delete nickname @config.delete nickname @config.save! puts "Deleted author #{nickname}" return true end |
.has_user?(nickname) ⇒ Boolean
Checks if the user exists and gives error and exit if so
163 164 165 166 167 168 169 |
# File 'lib/gas.rb', line 163 def self.has_user?(nickname) if @config.exists? nickname puts "Nickname #{nickname} already exists" return true end return false end |
.import(nickname) ⇒ Object
Imports current user from .gitconfig to .gas
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gas.rb', line 114 def self.import(nickname) return false if self.has_user?(nickname) user = @gitconfig.current_user if user user = User.new user.name, user.email, nickname @config.add user @config.save! puts 'Added author' puts user else puts 'No current user to import' end end |
.list ⇒ Object
Lists all authors
27 28 29 30 31 32 33 |
# File 'lib/gas.rb', line 27 def self.list puts puts 'Available users:' puts puts @config puts end |
.no_user?(nickname) ⇒ Boolean
Checks if the user exists and gives error and exit if not
153 154 155 156 157 158 159 |
# File 'lib/gas.rb', line 153 def self.no_user?(nickname) if !@config.exists? nickname puts "Nickname #{nickname} does not exist" return false end return true end |
.show ⇒ Object
Shows the current user
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gas.rb', line 36 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 |
.ssh(nickname) ⇒ Object
Adds an ssh key for the specified user
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gas.rb', line 78 def self.ssh(nickname) if nickname.nil? puts "Oh, so you'd like an elaborate explanation on how ssh key juggling works? Well pull up a chair!" puts puts "Gas can juggle ssh keys for you. It works best in a unix based environment (so at least use git bash or cygwin on a windows platform)." puts "You will be prompted if you would like to handle SSH keys when you create a new user." puts "If you are a long time user of gas, you can add ssh to an author by the command..." puts "\$ gas ssh NICKNAME" puts puts "Your ssh keys will be stored in ~/.gas/NICKNAME_id_rsa and automatically copied to ~/.ssh/id_rsa when you use the command..." puts "\$ gas use NICKNAME" puts "If ~/.ssh/id_rsa already exists, you will be prompted UNLESS that rsa file is already backed up in the .gas directory (I'm so sneaky, huh?)" puts puts "The unix command ssh-add is used in order to link up your rsa keys when you attempt to make an ssh connection (git push uses ssh keys of course)" puts puts "The ssh feature of gas offers you and the world ease of use, and even marginally enhanced privacy against corporate databases. Did you know that IBM built one of the first automated database systems? These ancient database machines (called tabulators) were used to facilitate the holocaust =(" else user = @config[nickname] # Prompt Remake this user's ssh keys? # check for ssh keys if !Ssh.corresponding_rsa_files_exist?(nickname) Ssh.setup_ssh_keys user Ssh.upload_public_key_to_github user else Ssh.setup_ssh_keys user Ssh.upload_public_key_to_github user end end end |
.use(nickname) ⇒ Object
Sets nickname as current user
49 50 51 52 53 54 55 56 |
# File 'lib/gas.rb', line 49 def self.use(nickname) return false unless self.no_user?(nickname) user = @config[nickname] @gitconfig.change_user user # daring change made here! Heads up Walle self.show end |