Improve workflow with devise generator.

This commit is contained in:
José Valim 2010-03-26 10:35:15 +01:00
parent ae729aedc3
commit e136573905
2 changed files with 13 additions and 2 deletions

View File

@ -12,6 +12,7 @@
* Move trackable logic to the model. * Move trackable logic to the model.
* E-mails now use any template available in the filesystem. Easy to create multipart e-mails. * E-mails now use any template available in the filesystem. Easy to create multipart e-mails.
* E-mails asks headers_for in the model to set the proper headers. * E-mails asks headers_for in the model to set the proper headers.
* Allow to specify haml in devise_views.
* bug fix * bug fix
* Do not use lock! on lockable since it's part of ActiveRecord API. * Do not use lock! on lockable since it's part of ActiveRecord API.

View File

@ -18,13 +18,19 @@ class DeviseGenerator < Rails::Generators::NamedBase
Time.now.utc.strftime("%Y%m%d%H%M%S") Time.now.utc.strftime("%Y%m%d%H%M%S")
end end
class_option :orm
class_option :migration, :type => :boolean, :default => orm_has_migration? class_option :migration, :type => :boolean, :default => orm_has_migration?
def invoke_orm_model def invoke_orm_model
if File.exists?(File.join(destination_root, model_path)) if model_exists?
say "* Model already exists. Adding Devise behavior." say "* Model already exists. Adding Devise behavior."
else else
invoke "model", [name], :migration => false invoke "model", [name], :migration => false, :orm => options[:orm]
unless model_exists?
abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
"Please create your model by hand before calling `rails g devise #{name}`."
end
end end
end end
@ -51,6 +57,10 @@ CONTENT
protected protected
def model_exists?
File.exists?(File.join(destination_root, model_path))
end
def model_path def model_path
@model_path ||= File.join("app", "models", "#{file_path}.rb") @model_path ||= File.join("app", "models", "#{file_path}.rb")
end end