Class: Asteroid::SSHKey
- Inherits:
-
Object
- Object
- Asteroid::SSHKey
- Defined in:
- lib/asteroid/ssh_key.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ssh_pub_key ⇒ Object
Returns the value of attribute ssh_pub_key.
Class Method Summary collapse
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(options = {}) ⇒ SSHKey
constructor
A new instance of SSHKey.
- #save ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SSHKey
8 9 10 11 |
# File 'lib/asteroid/ssh_key.rb', line 8 def initialize( = {}) @id = [:id] @name = [:name] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/asteroid/ssh_key.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/asteroid/ssh_key.rb', line 6 def name @name end |
#ssh_pub_key ⇒ Object
Returns the value of attribute ssh_pub_key.
6 7 8 |
# File 'lib/asteroid/ssh_key.rb', line 6 def ssh_pub_key @ssh_pub_key end |
Class Method Details
.all ⇒ Object
23 24 25 26 27 28 |
# File 'lib/asteroid/ssh_key.rb', line 23 def self.all keys = Provider.all.ssh_keys keys.map do |key| new id: key[:id], name: key[:name] end end |
.find(name) ⇒ Object
18 19 20 21 |
# File 'lib/asteroid/ssh_key.rb', line 18 def self.find(name) name = name.to_s all.select{|k| k.name == name}.first end |
Instance Method Details
#exists? ⇒ Boolean
13 14 15 16 |
# File 'lib/asteroid/ssh_key.rb', line 13 def exists? names = self.class.all.map{|k| k.name } names.include? @name end |
#save ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/asteroid/ssh_key.rb', line 30 def save if exists? puts "Key exists" else Digitalocean::SshKey.create( name: @name, ssh_pub_key: URI::escape(@ssh_pub_key) ) end end |