Class: DYAutomate::DYAutomateConfig

Inherits:
DYBaseObj
  • Object
show all
Defined in:
lib/DYAutomate/CustomConfig/DYAutomateConfig.rb

Constant Summary collapse

@@cachePath =

cache相关的路径

File.join(Dir.home(),'Documents','.DYAutomate')
@@configFilePath =
File.join(@@cachePath, 'DYConfigFile.rb')
@@configGitClonePath =
File.join(@@cachePath, 'Git')
@@logsDirPath =
File.join(@@cachePath, 'log')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DYBaseObj

#doCacheByYAML, fromFile, fromYAML

Constructor Details

#initializeDYAutomateConfig

Returns a new instance of DYAutomateConfig.



30
31
32
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 30

def initialize
  super
end

Instance Attribute Details

#codeSnippsets_git_urlObject

Returns the value of attribute codeSnippsets_git_url.



26
27
28
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 26

def codeSnippsets_git_url
  @codeSnippsets_git_url
end

#detail_gitObject

Returns the value of attribute detail_git.



21
22
23
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 21

def detail_git
  @detail_git
end

#detail_git_tagObject

Returns the value of attribute detail_git_tag.



22
23
24
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 22

def detail_git_tag
  @detail_git_tag
end

#detailObjObject

Returns the value of attribute detailObj.



24
25
26
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 24

def detailObj
  @detailObj
end

#templates_cache_pathObject

Returns the value of attribute templates_cache_path.



28
29
30
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 28

def templates_cache_path
  @templates_cache_path
end

#templates_git_urlObject

Returns the value of attribute templates_git_url.



25
26
27
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 25

def templates_git_url
  @templates_git_url
end

Class Method Details

.cachePathObject



34
35
36
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 34

def self.cachePath
  @@cachePath
end

.checkConfigFile?Boolean

检测config.rb是否存在

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 61

def self.checkConfigFile?
  path = File.join(@@configFilePath)
  unless File.exist?(path)
    creatConfigFile
    puts "*** At first ,you should edit the config file at path<#{@@configFilePath}>!!"

    `open #{@@configFilePath}`
  end
end

.configFilePathObject



38
39
40
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 38

def self.configFilePath
  @@configFilePath
end

.configGitClonePathObject



42
43
44
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 42

def self.configGitClonePath
  @@configGitClonePath
end

.creatConfigFileObject

创建一个ConfigFile例子



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 72

def self.creatConfigFile

  unless Dir.exist?(@@cachePath)
    Dir.mkdir(@@cachePath,0777)
  end

  File.new(@@configFilePath,'w+')

  f = File.open(@@configFilePath, "w+")
  demo = <<-EOF
  #DYAutomate 配置

  DYAutomateConfig.new do |c|
# 配置的git地址
c.detail_git = ""

# 配置的git tag
c.detail_git_tag = ""
  end
  EOF
  f.write(demo)
end

.loadConfigObject

从配置中心读取



51
52
53
54
55
56
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 51

def self.loadConfig
  checkConfigFile?
  cc = DYAutomateConfig.fromFile(@@configFilePath)
  cc.loadDetailFromGit if cc
  cc
end

.logsDirPathObject



46
47
48
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 46

def self.logsDirPath
  @@logsDirPath
end

Instance Method Details

#check_git_dirObject



111
112
113
114
115
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 111

def check_git_dir
  unless Dir.exist?(@@configGitClonePath)
    Dir.mkdir(@@configGitClonePath,0777)
  end
end

#check_git_versionObject



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 117

def check_git_version
  versionFile = File.join(@@configGitClonePath,"version")
  isSame = false
  if File.exist?(versionFile)
    versionContent = File.open(versionFile, 'r:utf-8', &:read)
    if versionContent
      isSame = versionContent.chomp.eql?(@detail_git_tag.chomp)
    end
  end
  isSame
end

#clone_gitObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 129

def clone_git
  check_git_dir
  if @detail_git_tag && @detail_git
    url = "#{@detail_git} --branch #{@detail_git_tag}"
    # url = "#{@git} "
    cloneOk = system "git clone #{url} #{@@configGitClonePath}"
    if cloneOk
      puts "clone #{url}成功。。。"
    else
      puts "clone #{url}失败!!"
    end
  else
    puts
  end
end

#loadDetailFromGitObject



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/DYAutomate/CustomConfig/DYAutomateConfig.rb', line 145

def loadDetailFromGit
  puts "加载配置。。。"
  check_git_dir
  unless check_git_version
    system("rm -rf #{@@configGitClonePath}")
    clone_git
  end
  path = File.join(@@configGitClonePath,'detailConfig.rb')
  @detailObj = DYAutomateConfigDetail.fromFile(path) if File.exist?(path)
  puts "加载配置成功。。。" if @detailObj
end