Class: ActiveRecord::Generators::ChatroomGenerator
- Inherits:
-
Base
- Object
- Base
- ActiveRecord::Generators::ChatroomGenerator
- Includes:
- Chatroom::Generators::OrmHelpers
- Defined in:
- lib/generators/active_record/chatroom_generator.rb
Instance Method Summary collapse
- #copy_chatroom_migration ⇒ Object
- #generate_model ⇒ Object
- #inject_chatroom_content ⇒ Object
- #migration_data ⇒ Object
Methods included from Chatroom::Generators::OrmHelpers
Instance Method Details
#copy_chatroom_migration ⇒ Object
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_model ⇒ Object
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_content ⇒ Object
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_data ⇒ Object
16 17 18 19 20 |
# File 'lib/generators/active_record/chatroom_generator.rb', line 16 def migration_data <<RUBY t.text :content, :null => false RUBY end |