Class: TorqueBox::Rails

Inherits:
Object
  • Object
show all
Defined in:
rake-support/lib/torquebox/rails.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) apply_template(root)



45
46
47
48
49
50
51
52
53
54
55
# File 'rake-support/lib/torquebox/rails.rb', line 45

def self.apply_template( root )
  print_rails_not_installed_and_exit unless rails_installed?
  require_generators
  if using_rails3_or_greater?
    generator = ::Rails::Generators::AppGenerator.new( [root], {}, :destination_root => root )
    Dir.chdir(root)
    generator.apply TorqueBox::Rails.template
  else
    ::Rails::TemplateRunner.new( TorqueBox::Rails.template )
  end
end

+ (Object) new_app(root)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'rake-support/lib/torquebox/rails.rb', line 28

def self.new_app( root )
  print_rails_not_installed_and_exit unless rails_installed?
  require_generators
  # Ensure ARGV[0] has the application path
  if ARGV.empty? || ARGV[0] != root
    ARGV.unshift( root )
  end
  ARGV << [ "-m", TorqueBox::Rails.template ]
  ARGV.flatten!
  if using_rails3_or_greater?
    ::Rails::Generators::AppGenerator.start
  else
    ::Rails::Generator::Base.use_application_sources!
    ::Rails::Generator::Scripts::Generate.new.run(ARGV, :generator => 'app')
  end
end


67
68
69
70
# File 'rake-support/lib/torquebox/rails.rb', line 67

def self.print_rails_not_installed_and_exit
  $stderr.puts "Rails not installed. Unable to load generators"
  exit 1
end

+ (Boolean) rails_installed?

Returns:

  • (Boolean)


63
64
65
# File 'rake-support/lib/torquebox/rails.rb', line 63

def self.rails_installed?
  defined? ::Rails::VERSION
end

+ (Object) require_generators



76
77
78
79
80
81
82
83
84
85
86
# File 'rake-support/lib/torquebox/rails.rb', line 76

def self.require_generators
  if using_rails3_or_greater?
    require 'rails/generators'
    require 'rails/generators/rails/app/app_generator'
  else
    require 'rails_generator'
    require 'rails_generator/generators/applications/app/app_generator'
    require 'rails_generator/generators/applications/app/template_runner'
    require 'rails_generator/scripts/generate'
  end
end

+ (Object) template



58
59
60
61
# File 'rake-support/lib/torquebox/rails.rb', line 58

def self.template
  File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'share',
            'rails', 'template.rb')
end

+ (Boolean) using_rails3_or_greater?

Returns:

  • (Boolean)


72
73
74
# File 'rake-support/lib/torquebox/rails.rb', line 72

def self.using_rails3_or_greater?
  ::Rails::VERSION::MAJOR >= 3
end