Class: ADD
- Inherits:
-
Object
- Object
- ADD
- Defined in:
- lib/add.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#password ⇒ Object
Returns the value of attribute password.
-
#server_alias ⇒ Object
Returns the value of attribute server_alias.
Instance Method Summary collapse
- #add_record(value) ⇒ Object
-
#initialize(server_alias, ip, password) ⇒ ADD
constructor
A new instance of ADD.
Constructor Details
#initialize(server_alias, ip, password) ⇒ ADD
Returns a new instance of ADD.
6 7 8 9 10 |
# File 'lib/add.rb', line 6 def initialize(server_alias,ip,password) self.server_alias = server_alias self.ip = ip self.password = password end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
3 4 5 |
# File 'lib/add.rb', line 3 def ip @ip end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/add.rb', line 3 def password @password end |
#server_alias ⇒ Object
Returns the value of attribute server_alias.
3 4 5 |
# File 'lib/add.rb', line 3 def server_alias @server_alias end |
Instance Method Details
#add_record(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/add.rb', line 12 def add_record(value) project_path = File.("~/.loginx/projects/") if Loginx::Exist.project_exist?(value) @info = {} detail = {} detail['ip'] = self.ip detail['password'] = self.password @info.store(self.server_alias,detail) @load = YAML::load(File.open("#{project_path}/#{value}.yml")) if @load.has_key?(self.server_alias) puts "the server alias already exists,will you overwrite it(y/n)" gets unless $_.chomp =='y' puts "nothing changed" exit 1 end end @load.merge!(@info) else puts "project #{value} does not exist , will you create it(y/n)" gets if $_.chomp == 'y' file = File.new("#{project_path}/#{value}.yml","w") file << "---\n" file << "example:\n" file << " ip: nil\n" file << " password: nil\n" file.close add_record(value) else puts "nothing changed" exit 1 end end File.open("#{project_path}/#{value}.yml","w") do |file| YAML.dump(@load,file) file.close #file.write @info.to_yaml puts "update successfully" end end |