Sha256: 7aa948fd575e185b5241528d5534bef92687d853262a776a69a7e91a7fb4842f

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

$:.unshift File.dirname(__FILE__)
%w[ rubygems optparse erb tempfile ].each { |f| require f }

module Ubiquo
  autoload :Options, 'ubiquo/options'
  autoload :Generator, 'ubiquo/generator'

  class App
    class << self
      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 ? '3.2.0.rc2' : '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 new #{options[:app_name]} -m #{tpl.path}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ubiquo-0.9.0.b8 lib/ubiquo.rb
ubiquo-0.9.0.b6 lib/ubiquo.rb
ubiquo-0.9.0.b5 lib/ubiquo.rb
ubiquo-0.9.0.b4 lib/ubiquo.rb