Class: Pindo::PindoUserLocalConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/config/pindouserlocalconfig.rb

Defined Under Namespace

Modules: PindoUserLocalMixin

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePindoUserLocalConfig

Returns a new instance of PindoUserLocalConfig.



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
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 12

def initialize( )
  
  # puts "initialize Pindoconfig"
  if !File.exist?(Pindoconfig.instance.pindo_dir) 
    FileUtils.mkdir(Pindoconfig.instance.pindo_dir)
  end

  @pindo_user_local_config_json = nil

  @pindo_user_local_config_file = File.join(File::expand_path(Pindoconfig.instance.pindo_dir), ".pindo_use_local_config.json")

  if File.exist?(@pindo_user_local_config_file) 
    begin
      @pindo_user_local_config_json = JSON.parse(File.read(@pindo_user_local_config_file))  
    rescue => exception
      puts "Error !!! +++++++++++ load Pindo local config error !!!"
    end

    if @pindo_user_local_config_json.nil?
      begin
        FileUtils.rm_rf(@pindo_user_local_config_file)
      rescue => exception
        
      end
    end
  end
end

Class Attribute Details

.instanceObject



104
105
106
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 104

def self.instance
  @instance ||= new
end

Instance Attribute Details

#pindo_user_local_config_jsonObject

Returns the value of attribute pindo_user_local_config_json.



10
11
12
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 10

def pindo_user_local_config_json
  @pindo_user_local_config_json
end

Class Method Details

.reload_instanceObject



100
101
102
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 100

def self.reload_instance
  @instance = new
end

Instance Method Details

#get_last_work_project_arrayObject



60
61
62
63
64
65
66
67
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 60

def get_last_work_project_array()
    last_work_project_array = nil
    if !@pindo_user_local_config_json.nil?
        last_work_project_array = @pindo_user_local_config_json["last_work_project_array"] || []
    end
    last_work_project_array = last_work_project_array || []
    return last_work_project_array;
end

#read_local_wechat_urlObject



40
41
42
43
44
45
46
47
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 40

def read_local_wechat_url

  local_wechat_url = nil
  if !@pindo_user_local_config_json.nil?
      local_wechat_url = @pindo_user_local_config_json["local_wechat_url"]
  end
  return local_wechat_url;
end

#write_last_work_project(proj_name: nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 70

def write_last_work_project(proj_name:nil)
    if proj_name.nil? 
      return
    end
    if proj_name.length < 1
      return
    end

    @pindo_user_local_config_json = @pindo_user_local_config_json || {}

    last_work_project_array = @pindo_user_local_config_json["last_work_project_array"] || []  

    
    # 从数组中删除目标字符串
    last_work_project_array.delete(proj_name)
    # 将目标字符串插入到数组末尾
    last_work_project_array.unshift(proj_name)
    # 如果数组长度超过5,删除第一个元素
    last_work_project_array.pop if last_work_project_array.length > 6
    last_work_project_array.pop if last_work_project_array.length > 6

    @pindo_user_local_config_json["last_work_project_array"] = last_work_project_array
    File.open(@pindo_user_local_config_file, "w") do |file|
        file.write(JSON.pretty_generate(@pindo_user_local_config_json))
        file.close
    end
end

#write_local_wechat_url(wechat_msg_url: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/pindo/config/pindouserlocalconfig.rb', line 49

def write_local_wechat_url(wechat_msg_url:nil)
  
    @pindo_user_local_config_json =  @pindo_user_local_config_json || {}
    @pindo_user_local_config_json["local_wechat_url"] = wechat_msg_url
    File.open(@pindo_user_local_config_file, "w") do |file|
        file.write(JSON.pretty_generate(@pindo_user_local_config_json))
        file.close
    end
end