Class: Stool::Command::LibPool::Add

Inherits:
Stool::Command::LibPool show all
Defined in:
lib/stool/Command/LibPool/Add.rb

Instance Method Summary collapse

Methods inherited from Stool::Command::LibPool

existLocalAndClone, pools_from_config

Methods inherited from Stool::Command

#checkConfigFile, options, #pp

Constructor Details

#initialize(argv) ⇒ Add

def self.options

[
    ['--progress', 'Show the progress of cloning the spec repository'],
].concat(super)

end



25
26
27
28
29
30
31
# File 'lib/stool/Command/LibPool/Add.rb', line 25

def initialize(argv)
  puts 'Add ---  init'
  @pInfo.name = argv.shift_argument
  @pInfo.path = argv.shift_argument
  # @progress = argv.flag?('progress')
  super
end

Instance Method Details

#cachePathObject



86
87
88
89
# File 'lib/stool/Command/LibPool/Add.rb', line 86

def cachePath
  path = "#{@@PathForCache + @name + '.yaml'}"
  path.to_s
end

#doCacheByYamlToPath(cacheDirPath, fileName) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/stool/Command/LibPool/Add.rb', line 76

def doCacheByYamlToPath(cacheDirPath,fileName)
  puts "....do cache to #{cacheDirPath}"
  unless File::exists?(cacheDirPath)
    Dir.mkdir(cacheDirPath,0777)
  end
  File.open(File.join(cacheDirPath,fileName) + '.yaml', "w") { |file|
    YAML.dump(self, file)
  }
end

#hadCached?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
# File 'lib/stool/Command/LibPool/Add.rb', line 66

def hadCached?
  puts "@PathForCache = #{@@PathForCache}"
  puts "@name = #{@name}"

  obj = nil
  if File.exist?(self.cachePath)
    obj = YAML::load(File.open(self.cachePath))
  end
end

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stool/Command/LibPool/Add.rb', line 46

def run
  puts 'Add ---  run'
  #do cache
  obj = hadCached?
  if obj
    obj.path = @path
  else
    doCacheByYamlToPath(@@PathForCache,@name)
  end

  # section = "Cloning spec repo `#{@name}` from `#{@url}`"
  # section << " (branch `#{@branch}`)" if @branch
  # UI.section(section) do
  #   create_repos_dir
  #   clone_repo
  #   checkout_branch
  #   config.sources_manager.sources([dir.basename.to_s]).each(&:verify_compatibility!)
  # end
end

#validate!Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/stool/Command/LibPool/Add.rb', line 33

def validate!
  super
  puts 'Add ---  validate!'
  unless @pInfo.name && @pInfo.path
    help! 'Adding a libPool needs a `NAME` and a `PATH`.'
  end

  unless File.exist?(@path)
    raise Informative,
          'To add a pool, please give a ensure the path of folder is exist.'
  end
end