Class: Stool::Config

Inherits:
BaseObj show all
Defined in:
lib/stool/Core/Config.rb

Constant Summary collapse

@@cachePath =

cache相关的路径

File.join(Dir.home(),'stool')
@@configFilePath =
File.join(@@cachePath, 'ConfigFile.rb')
@@logsDirPath =
File.join(@@cachePath, 'log')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObj

#doCacheByYAML, fromFile, fromYAML

Constructor Details

#initializeConfig

Returns a new instance of Config.



26
27
28
29
30
31
32
33
# File 'lib/stool/Core/Config.rb', line 26

def initialize
  @repoCachePath = File.join(Dir.home,'.cocoapods/repos')
  @pools = []
  @tasks = []
  @checkRepos = []
  @checkReposSheets = []
  super
end

Instance Attribute Details

#checkReposObject

repo pod库的统计



23
24
25
# File 'lib/stool/Core/Config.rb', line 23

def checkRepos
  @checkRepos
end

#checkReposSheetsObject

Returns the value of attribute checkReposSheets.



24
25
26
# File 'lib/stool/Core/Config.rb', line 24

def checkReposSheets
  @checkReposSheets
end

#poolsObject

本地lib池子



16
17
18
# File 'lib/stool/Core/Config.rb', line 16

def pools
  @pools
end

#repoCachePathObject

cocoapods的repo缓存路径



20
21
22
# File 'lib/stool/Core/Config.rb', line 20

def repoCachePath
  @repoCachePath
end

#tasksObject

主工程



18
19
20
# File 'lib/stool/Core/Config.rb', line 18

def tasks
  @tasks
end

Class Method Details

.checkConfigFile?Boolean

检测config.rb是否存在

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
# File 'lib/stool/Core/Config.rb', line 63

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

.creatConfigFileObject

创建一个ConfigFile例子



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/stool/Core/Config.rb', line 74

def self.creatConfigFile

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

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

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

    #stool 配置

    Config.new do |c|

      #添加一个本地lib pool,池中是你clone下来的各个pod
      #name - 根据爱好,随意取
      #path - lib pool的本地路径
      c.addPool do |p|
        p.name = '本地lib池 - 1'
        p.path = ''
      end

      #再添加一个本地lib pool
      # c.addPool do |p|
      #     p.name = '本地lib池 - 2'
      #     p.path = ''
      # end

      #添加一个项目工程,iOS-workspace工程
      #name - 随意取
      #tag - 命令操作需要,工程的唯一标识
      #path - 路径目下要有workspace/podfile文件
      #addLocalLib - 项目使用的本地lib(再无需手动修改Podfile),默认都是源码
      #addOtherLibUseCode - 非本地lib,配置使用源码
      #allLibsUseCode - 是否所有lib都使用源码,默认false
      c.addTask do |t|
        t.name = 'workspace主工程-1'
        t.tag = '1'
        t.path = ''
        t.addLocalLib(['pod1',
          'pod2',
          'pod3'])
        t.addOtherLibUseCode(['pod4'])
        #t.allLibsUseCode
      end

      #设置pod库统计时,查询的repos、Excel中sheet的名字

    end
  EOF

  f.write(demo)
end

.loadConfigObject

从配置中心读取



40
41
42
43
44
# File 'lib/stool/Core/Config.rb', line 40

def self.loadConfig
  checkConfigFile?
  cc = Config::fromFile(@@configFilePath)
  cc
end

.logsDirPathObject



35
36
37
# File 'lib/stool/Core/Config.rb', line 35

def self.logsDirPath
  @@logsDirPath
end

Instance Method Details

#addPool {|pInfo| ... } ⇒ Object

添加一个本地libPool

Yields:

  • (pInfo)


47
48
49
50
51
# File 'lib/stool/Core/Config.rb', line 47

def addPool
  pInfo = PoolInfo.new()
  @pools.push(pInfo)
  yield pInfo if block_given?
end

#addTask {|tInfo| ... } ⇒ Object

添加一个workspace

Yields:

  • (tInfo)


54
55
56
57
58
# File 'lib/stool/Core/Config.rb', line 54

def addTask
  tInfo = TaskInfo.new()
  @tasks.push(tInfo)
  yield tInfo if block_given?
end