Class: PF::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/pf/profile/profile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProfile

Returns a new instance of Profile.



8
9
10
# File 'lib/pf/profile/profile.rb', line 8

def initialize
  @qiniu = QiniuProfile.new(self)
end

Instance Attribute Details

#qiniuObject

Returns the value of attribute qiniu.



6
7
8
# File 'lib/pf/profile/profile.rb', line 6

def qiniu
  @qiniu
end

Class Method Details

.create_profile_if_not_existObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/pf/profile/profile.rb', line 23

def self.create_profile_if_not_exist
  path = profile_path
  require 'fileutils'
  unless File.directory?(File.dirname(path))
    FileUtils.mkdir_p(File.dirname(path))
  end
  unless File.exist?(path)
    Profile.new.save
  end
end

.profileObject



38
39
40
41
42
# File 'lib/pf/profile/profile.rb', line 38

def self.profile
  create_profile_if_not_exist
  file = profile_path
  YAML.load_file(file)
end

.profile_file_for_writeObject



34
35
36
# File 'lib/pf/profile/profile.rb', line 34

def self.profile_file_for_write
  File.open(profile_path, "w+")
end

.profile_pathObject



18
19
20
21
# File 'lib/pf/profile/profile.rb', line 18

def self.profile_path
  pf_home = File.join(Dir.home(), '.pf')
  File.join(pf_home, "profile.yaml")
end

.qiniuObject



44
45
46
# File 'lib/pf/profile/profile.rb', line 44

def self.qiniu
  profile.qiniu
end

Instance Method Details

#saveObject



12
13
14
15
16
# File 'lib/pf/profile/profile.rb', line 12

def save
  file = self.class.profile_file_for_write
  file.write(to_yaml)
  file.close
end