Class: Devkit::Identity
- Inherits:
-
Object
- Object
- Devkit::Identity
- Defined in:
- lib/devkit/identity.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#full_name ⇒ Object
Returns the value of attribute full_name.
-
#github_id ⇒ Object
Returns the value of attribute github_id.
-
#ssh_identity ⇒ Object
Returns the value of attribute ssh_identity.
Class Method Summary collapse
- .add! ⇒ Object
- .choose!(nick_name) ⇒ Object
- .drop! ⇒ Object
- .expire_in(time) ⇒ Object
- .list ⇒ Object
- .remove!(nick_name) ⇒ Object
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/devkit/identity.rb', line 6 def email @email end |
#full_name ⇒ Object
Returns the value of attribute full_name.
6 7 8 |
# File 'lib/devkit/identity.rb', line 6 def full_name @full_name end |
#github_id ⇒ Object
Returns the value of attribute github_id.
6 7 8 |
# File 'lib/devkit/identity.rb', line 6 def github_id @github_id end |
#ssh_identity ⇒ Object
Returns the value of attribute ssh_identity.
6 7 8 |
# File 'lib/devkit/identity.rb', line 6 def ssh_identity @ssh_identity end |
Class Method Details
.add! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/devkit/identity.rb', line 51 def add! existing_identities = Devkit::Core.identities nick_name = ask("Nick Name: ", String).to_s if Devkit::Core.identities[nick_name] puts "identity already exists" list else new_identity = Hash.new new_identity[nick_name] = Hash.new new_identity[nick_name]["Full Name"] = ask("Full Name: ", String).to_s new_identity[nick_name]["Email"] = ask("Email: ", String).to_s new_identity[nick_name]["Github Id"] = ask("Github Id: ", String).to_s new_identity[nick_name]["SSH Identity"] = ask("SSH Identity: ", String).to_s new_identity[nick_name]["Expires In"] = EXPIRY_TIME Devkit::Core.clear_existing_devkit_file File.open(Devkit::DEVKIT_FILE_PATH, 'a+') do |f| f.write(existing_identities.merge(new_identity).to_yaml) end list end end |
.choose!(nick_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/devkit/identity.rb', line 28 def choose!(nick_name) identity = Devkit::Core.identities[nick_name] if identity Devkit::GitIdentity.choose(identity) Devkit::SshIdentity.choose(identity) expire_in(identity['Expires In']) else puts "#{nick_name} does not exist. Please try devkit --list to double check." end end |
.drop! ⇒ Object
39 40 41 42 |
# File 'lib/devkit/identity.rb', line 39 def drop! Devkit::GitIdentity.drop Devkit::SshIdentity.drop end |
.expire_in(time) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/devkit/identity.rb', line 44 def expire_in(time) time ||= Devkit::EXPIRY_TIME command = "sleep #{time} && #{Devkit.bin_path} --drop&" puts "Setting the identity to expire in #{time} seconds" system(command) end |
.list ⇒ Object
9 10 11 |
# File 'lib/devkit/identity.rb', line 9 def list puts Devkit::Core.identities.to_yaml end |
.remove!(nick_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/devkit/identity.rb', line 13 def remove!(nick_name) existing_identities = Devkit::Core.identities identity = existing_identities[nick_name] if identity && agree("Are you sure you want to delete #{identity['Full Name']} (y/n)?", true) new_identities = existing_identities.reject { |dev| dev == nick_name } Devkit::Core.clear_existing_devkit_file File.open(Devkit::DEVKIT_FILE_PATH, 'a+') do |f| f.write(new_identities.to_yaml) end else puts "#{nick_name} does not exist in .devkit identities" #self.list end end |