Class: Rich::Generators::CmsAdminGenerator

Inherits:
RichCms::Generators::Base show all
Includes:
Rails::Generators::Migration, RichCms::Generators::Migration
Defined in:
lib/generators/rich/cms_admin/cms_admin_generator.rb

Instance Method Summary collapse

Methods included from RichCms::Generators::Migration

included

Methods inherited from RichCms::Generators::Base

source_root

Instance Method Details

#derive_authentication_logicObject



18
19
20
21
# File 'lib/generators/rich/cms_admin/cms_admin_generator.rb', line 18

def derive_authentication_logic
  @logic = "Devise"
  @logic = "Authlogic" if options[:authlogic]
end

#generate_authenticated_modelObject



38
39
40
41
42
43
44
# File 'lib/generators/rich/cms_admin/cms_admin_generator.rb', line 38

def generate_authenticated_model
  if options[:bundle]
    gem @logic.underscore, {"devise" => "~> 1.1.5", "authlogic" => "~> 2.1.6"}[@logic.underscore]
    run "bundle install"
  end
  send :"generate_#{@logic.underscore}_assets"
end

#migrateObject



46
47
48
# File 'lib/generators/rich/cms_admin/cms_admin_generator.rb', line 46

def migrate
  rake "db:migrate" if options[:migrate]
end

#register_authenticationObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/rich/cms_admin/cms_admin_generator.rb', line 23

def register_authentication
  filename = "config/initializers/enrichments.rb"
  line     = "Rich::Cms::Auth.setup do |config|"

  create_file filename unless File.exists?(filename)
  return if File.open(filename).readlines.collect(&:strip).include? line.strip

  File.open(filename, "a+") do |file|
    file << "#{line}\n"
    file << "  config.logic = :#{@logic.underscore}\n"
    file << "  config.klass = \"#{model_class_name}\"\n"
    file << "end"
  end
end