diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-23 14:42:59 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-23 16:53:47 +0200 |
commit | 1845675822fef4ead89b8919da56c4fadb145e56 (patch) | |
tree | b536919097f2d52fcdc6502d39018bc38f0af58e /railties/lib/generator/generators | |
parent | f03890e151d7a8b9cc413ea9955efc95ff4fbfe6 (diff) | |
download | rails-1845675822fef4ead89b8919da56c4fadb145e56.tar.gz rails-1845675822fef4ead89b8919da56c4fadb145e56.tar.bz2 rails-1845675822fef4ead89b8919da56c4fadb145e56.zip |
Added metal generator.
Diffstat (limited to 'railties/lib/generator/generators')
4 files changed, 42 insertions, 3 deletions
diff --git a/railties/lib/generator/generators/app/app_generator.rb b/railties/lib/generator/generators/app/app_generator.rb index 6f5cb5f2c6..3eb9b8c79a 100644 --- a/railties/lib/generator/generators/app/app_generator.rb +++ b/railties/lib/generator/generators/app/app_generator.rb @@ -3,10 +3,8 @@ require 'digest/md5' require 'active_support/secure_random' module Rails::Generators - class App < Base + class AppGenerator < Base DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db ) - - namespace "rails:app" add_shebang_option! argument :app_path, :type => :string @@ -182,6 +180,10 @@ module Rails::Generators ActiveSupport::SecureRandom.hex(64) end + def self.banner + "#{$0} #{self.arguments.map(&:usage).join(' ')} [options]" + end + def mysql_socket @mysql_socket ||= [ "/tmp/mysql.sock", # default diff --git a/railties/lib/generator/generators/metal/USAGE b/railties/lib/generator/generators/metal/USAGE new file mode 100644 index 0000000000..123ec6c03f --- /dev/null +++ b/railties/lib/generator/generators/metal/USAGE @@ -0,0 +1,8 @@ +Description: + Cast some metal! + +Examples: + `./script/generate metal poller` + + This will create: + Metal: app/metal/poller.rb diff --git a/railties/lib/generator/generators/metal/metal_generator.rb b/railties/lib/generator/generators/metal/metal_generator.rb new file mode 100644 index 0000000000..1c59a4e90a --- /dev/null +++ b/railties/lib/generator/generators/metal/metal_generator.rb @@ -0,0 +1,17 @@ +require File.dirname(__FILE__) + '/../../base' + +module Rails::Generators + class MetalGenerator < Base + argument :file_name, :type => :string + + def create_file + template "metal.rb", "app/metal/#{file_name}.rb" + end + + protected + + def class_name + file_name.classify + end + end +end diff --git a/railties/lib/generator/generators/metal/templates/metal.rb b/railties/lib/generator/generators/metal/templates/metal.rb new file mode 100644 index 0000000000..e94982b69a --- /dev/null +++ b/railties/lib/generator/generators/metal/templates/metal.rb @@ -0,0 +1,12 @@ +# Allow the metal piece to run in isolation +require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) + +class <%= class_name %> + def self.call(env) + if env["PATH_INFO"] =~ /^\/<%= file_name %>/ + [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] + else + [404, {"Content-Type" => "text/html"}, ["Not Found"]] + end + end +end |