Method: Codger::Manager#generator

Defined in:
lib/codger/manager.rb

#generator(id) ⇒ Object

Creates a Generator, currently always a Skeleton. id can be:

  • a filesystem path, which will be used directly

  • a git uri, which will be cloned to a temporary directory

  • a substring of the identifier of a cached skeleton



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/codger/manager.rb', line 50

def generator(id)
  if File.exists? id
    clone = id
    id = File.expand_path id
  elsif cached = match_cached_identifier(id)
    id, clone = cached
    git = Git.open(clone)
    # https://github.com/schacon/ruby-git/issues/32
    begin
      git.lib.send(:command, 'pull')
    rescue StandardError => ex
      puts "Warning: could not update cached clone: #{ex.inspect}"
    end
  else
    clone = Dir.mktmpdir
    Git.clone id, clone
    at_exit do
      raise "I'm scared to delete #{clone}" unless clone.size > 10 # just being paranoid before rm_rf'ing
      FileUtils.rm_rf clone
    end
  end
  Skeleton.new clone, id
end