Class: Profile
- Inherits:
-
Object
- Object
- Profile
- Defined in:
- lib/ssport/profile.rb
Instance Method Summary collapse
- #dealrc ⇒ Object
- #genrc(alias_name) ⇒ Object
-
#initialize(options) ⇒ Profile
constructor
A new instance of Profile.
- #list ⇒ Object
- #loadrc ⇒ Object
- #saverc ⇒ Object
Constructor Details
#initialize(options) ⇒ Profile
Returns a new instance of Profile.
6 7 8 9 |
# File 'lib/ssport/profile.rb', line 6 def initialize() @options = @alias_name = @options[:alias] end |
Instance Method Details
#dealrc ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ssport/profile.rb', line 29 def dealrc if @alias_name server = @options[:server] username = @options[:username] pass = @options[:pass] if server || username || pass return saverc else return loadrc end end return nil end |
#genrc(alias_name) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ssport/profile.rb', line 11 def genrc(alias_name) if !File.directory?(File.("~/.ssport")) `mkdir ~/.ssport` end File. "~/.ssport/#{alias_name}.rc" end |
#list ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ssport/profile.rb', line 18 def list alias_names = Dir[File. "~/.ssport/*"].select{ |f| File.file? f }.map{ |f| File.basename f, ".rc"} puts '----------Alias Name----------'.colorize(:yellow) alias_names.each do |name| @alias_name = name rc = loadrc puts "#{name} : #{rc[:server]}".colorize(:green) end puts '--------------END-------------'.colorize(:yellow) end |
#loadrc ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ssport/profile.rb', line 52 def loadrc if @alias_name rc_content = File.read genrc(@alias_name) rc = JSON.parse(rc_content) final_rc = rc.collect{|k,v| [k.to_sym, v]}.to_h return final_rc else puts "Don't find server alias name profile.".colorize(:red) end return nil end |
#saverc ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/ssport/profile.rb', line 43 def saverc if @alias_name rc = JSON.pretty_generate(@options) File.write genrc(@alias_name), rc return @options end return nil end |