Class: Delete_p
- Inherits:
-
Object
- Object
- Delete_p
- Defined in:
- lib/delete.rb
Instance Attribute Summary collapse
-
#server_alias ⇒ Object
Returns the value of attribute server_alias.
Instance Method Summary collapse
- #del_file(value) ⇒ Object
- #del_record(value) ⇒ Object
-
#initialize(server_alias = nil) ⇒ Delete_p
constructor
A new instance of Delete_p.
Constructor Details
#initialize(server_alias = nil) ⇒ Delete_p
Returns a new instance of Delete_p.
5 6 7 |
# File 'lib/delete.rb', line 5 def initialize(server_alias = nil) self.server_alias = server_alias end |
Instance Attribute Details
#server_alias ⇒ Object
Returns the value of attribute server_alias.
3 4 5 |
# File 'lib/delete.rb', line 3 def server_alias @server_alias end |
Instance Method Details
#del_file(value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/delete.rb', line 41 def del_file(value) project_path = File.("~/.loginx/projects/") if Loginx::Exist.project_exist?(value) puts "Are you sure to delete it(y/n)" gets if $_.chomp =='y' File.delete("#{project_path}/#{value}.yml") puts "update successfully" else puts "nothing changed" exit 1 end else puts "project #{value} does not exist!" exit 1 end end |
#del_record(value) ⇒ Object
9 10 11 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 |
# File 'lib/delete.rb', line 9 def del_record(value) project_path = File.("~/.loginx/projects/") if Loginx::Exist.project_exist?(value) @load = YAML::load(File.open("#{project_path}/#{value}.yml")) if !@load.has_key?(self.server_alias) puts "sorry the server alias does not exist" exit 1 end puts "Are you sure to delete it(y/n)" gets if $_.chomp =='y' @load.delete(self.server_alias) else puts "nothing changed" exit 1 end else puts "project #{value} does not exist!" exit 1 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 |