2017-12-21 17:36:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-15 12:56:05 +00:00
|
|
|
require 'rails/generators/base'
|
2011-05-28 13:44:54 +00:00
|
|
|
require 'securerandom'
|
2010-06-13 11:04:24 +00:00
|
|
|
|
|
|
|
module Devise
|
|
|
|
module Generators
|
2016-02-15 12:16:43 +00:00
|
|
|
MissingORMError = Class.new(Thor::Error)
|
|
|
|
|
2010-06-13 11:04:24 +00:00
|
|
|
class InstallGenerator < Rails::Generators::Base
|
2010-07-27 14:14:09 +00:00
|
|
|
source_root File.expand_path("../../templates", __FILE__)
|
2010-06-13 11:04:24 +00:00
|
|
|
|
|
|
|
desc "Creates a Devise initializer and copy locale files to your application."
|
|
|
|
class_option :orm
|
|
|
|
|
|
|
|
def copy_initializer
|
2016-02-15 12:16:43 +00:00
|
|
|
unless options[:orm]
|
|
|
|
raise MissingORMError, <<-ERROR.strip_heredoc
|
|
|
|
An ORM must be set to install Devise in your application.
|
|
|
|
|
|
|
|
Be sure to have an ORM like Active Record or Mongoid loaded in your
|
|
|
|
app or configure your own at `config/application.rb`.
|
|
|
|
|
|
|
|
config.generators do |g|
|
|
|
|
g.orm :your_orm_gem
|
|
|
|
end
|
|
|
|
ERROR
|
|
|
|
end
|
|
|
|
|
2010-06-13 11:04:24 +00:00
|
|
|
template "devise.rb", "config/initializers/devise.rb"
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_locale
|
2010-07-27 14:14:09 +00:00
|
|
|
copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
2010-06-13 11:04:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_readme
|
2010-07-27 14:14:09 +00:00
|
|
|
readme "README" if behavior == :invoke
|
2010-06-13 11:04:24 +00:00
|
|
|
end
|
2014-01-13 23:24:21 +00:00
|
|
|
|
|
|
|
def rails_4?
|
|
|
|
Rails::VERSION::MAJOR == 4
|
|
|
|
end
|
2010-06-13 11:04:24 +00:00
|
|
|
end
|
|
|
|
end
|
2011-05-28 13:44:54 +00:00
|
|
|
end
|