Class: BiocGem::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/bioc_gem/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Command

Returns a new instance of Command.



10
11
12
13
# File 'lib/bioc_gem/command.rb', line 10

def initialize(argv = ARGV)
  @argv = argv.clone
  @parser = Parser.new
end

Instance Attribute Details

#parserObject

Returns the value of attribute parser.



8
9
10
# File 'lib/bioc_gem/command.rb', line 8

def parser
  @parser
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
# File 'lib/bioc_gem/command.rb', line 15

def run
  parser.parse!(@argv)

  command = parser.command
  options = parser.options

  public_send("run_#{command}", options) if [:new].include?(command)
end

#run_new(options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bioc_gem/command.rb', line 24

def run_new(options)
  config = parser.options
  require_name     = config.gem_require_name
  package_name     = config.bioc_package_name
  output_directory = config.output_directory

  target = File.join(output_directory, package_name)

  base = File.expand_path("../../template/newgem", __dir__)

  Dir.mktmpdir do |tmpdir|
    Dir.glob("**/*", File::FNM_DOTMATCH, base: base) do |f|
      src = File.expand_path(f, base)
      next unless File.file?(src)

      str = File.read(src)
      erb = ERB.new(str)
      str = erb.result(binding)

      trg = File.expand_path(f, tmpdir)
      fname = File.basename(trg, ".tt")
      fname.gsub!("new_gem_entry", config.gem_require_name)
      dirname = File.dirname(trg)
      FileUtils.mkdir_p(dirname)
      File.write(File.join(dirname, fname), str)
    end
    FileUtils.cp_r(tmpdir, target)
  end

  warn "Created #{target}"
end