Class: Rich::Generators::CmsContentGenerator

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

Instance Method Summary collapse

Methods included from RichCms::Generators::Migration

included

Methods inherited from RichCms::Generators::Base

source_root

Instance Method Details

#generate_migrationObject



31
32
33
# File 'lib/generators/rich/cms_content/cms_content_generator.rb', line 31

def generate_migration
  migration_template "migration.rb", "db/migrate/create_#{table_name}"
end

#generate_modelObject



27
28
29
# File 'lib/generators/rich/cms_content/cms_content_generator.rb', line 27

def generate_model
  invoke "active_record:model", [model_file_name], :migration => false
end

#migrateObject



35
36
37
# File 'lib/generators/rich/cms_content/cms_content_generator.rb', line 35

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

#register_contentObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/rich/cms_content/cms_content_generator.rb', line 15

def register_content
  filename = "config/initializers/enrichments.rb"
  line     = "\nRich::Cms::Engine.register(\".#{model_file_name}\", {:class_name => \"#{model_class_name}\"})"

  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
  end
end