Class: Ubiquo::App

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

Class Method Summary collapse

Class Method Details

.run!(arguments) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
55
# File 'lib/ubiquo.rb', line 10

def run!(arguments)
  env_opts = Options.new(ENV['UBIQUO_OPTS'].split(' ')) if ENV['UBIQUO_OPTS']
  options = Options.new(arguments)
  options = options.merge(env_opts) if env_opts

  # We need this because sometimes we upgrade edge but no stable
  options[:rails] = options[:template] == :edge ? '2.3.14' : '2.3.14'

  unless Gem.available?('rails', options[:rails])
    $stderr.puts "Sorry ubiquo needs rails #{options[:rails]} to work properly."
    options[:show_help] = true
  end

  if `which git` == ''
    $stderr.puts "Sorry you need to install git (> 1.5.3). See http://git-scm.com/"
    options[:show_help] = true
  end

  if options[:version]
    $stdout.puts options[:version]
    return 0
  end

  if options[:invalid_argument]
    $stderr.puts options[:invalid_argument]
    options[:show_help] = true
  end

  if options[:show_help]
    $stderr.puts options.opts
    return 1
  end

  if options[:app_name].nil? || options[:app_name].squeeze.strip == ""
    $stderr.puts options.opts
    return 1
  end

  skeleton = File.dirname(__FILE__) + "/ubiquo/template.erb"
  tpl = Tempfile.new('tmp')
  File.open(tpl.path, 'w') do |file|
    file.write Generator.build_template(options, skeleton)
  end
  tpl.sync=true
  system("rails _#{options[:rails]}_ -m #{tpl.path} #{options[:app_name]}")
end