Class: Gemical::Commands::Bundle

Inherits:
Base
  • Object
show all
Defined in:
lib/gemical/commands/bundle.rb

Defined Under Namespace

Classes: Evaluator

Instance Method Summary collapse

Instance Method Details

#create(args, options) ⇒ Object



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
# File 'lib/gemical/commands/bundle.rb', line 25

def create(args, options)
  gemfile = current_path.join('Gemfile')
  terminate "Unable to find a Gemfile in #{current_path}" unless gemfile.file?
  terminate "Gemfile in #{current_path} is not writable" unless gemfile.writable?

  evaluation = Evaluator.new(gemfile)
  terminate "Gemfile doesn't seem to be valid" if evaluation.sources.empty?

  authenticate!
  vault = current_vault(options)

  if evaluation.sources.any? {|s| s.to_s.include?(vault.token) }
    terminate "Vault '#{vault}' is already sourced in your Gemfile."
  end

  source = gemfile.open('r')
  output = Tempfile.new "Gemfile"

  while string = source.gets
    output << string
    if string =~ /^(\s*)source\b/
      output << "#{$1}source 'http://#{vault.token}@bundle.gemical.com'\n"
    end
  end
  output.close

  FileUtils.cp output.path, source.path
  success "Vault '#{vault}' was added as a source to your Gemfile."
end