Class: ActiveRecord::Generators::ChatroomGenerator

Inherits:
Base
  • Object
show all
Includes:
Chatroom::Generators::OrmHelpers
Defined in:
lib/generators/active_record/chatroom_generator.rb

Instance Method Summary collapse

Methods included from Chatroom::Generators::OrmHelpers

#model_contents

Instance Method Details

#copy_chatroom_migrationObject



12
13
14
# File 'lib/generators/active_record/chatroom_generator.rb', line 12

def copy_chatroom_migration
  migration_template "migration.rb", "db/migrate/chatroom_create_#{table_name}"
end

#generate_modelObject



22
23
24
# File 'lib/generators/active_record/chatroom_generator.rb', line 22

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

#inject_chatroom_contentObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/active_record/chatroom_generator.rb', line 26

def inject_chatroom_content
  content = model_contents

  class_path = if namespaced?
                 class_name.to_s.split("::")
               else
                 [class_name]
               end
  indent_depth = class_path.size - 1

  content = content.split("\n").map { |line| "  " * indent_depth + line }.join("\n") << "\n"

  inject_into_class(model_path, class_path.last, content) if model_exists?
end

#migration_dataObject



16
17
18
19
20
# File 'lib/generators/active_record/chatroom_generator.rb', line 16

def migration_data
"t.text :content, :null => false\n"
end