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
11
# File 'lib/pf/profile/profile.rb', line 8

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

Instance Attribute Details

#boxObject

Returns the value of attribute box.



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

def box
  @box
end

#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

.boxObject



49
50
51
52
53
54
55
56
# File 'lib/pf/profile/profile.rb', line 49

def self.box
  p = profile
  if p.box.nil?
    p.box = BoxProfile.new(p)
  end
  p.save
  p.box
end

.create_profile_if_not_existObject



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

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



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

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

.profile_file_for_writeObject



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

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

.profile_pathObject



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

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

.qiniuObject



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

def self.qiniu
  profile.qiniu
end

Instance Method Details

#saveObject



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

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