Class: ModelTokenizer::Generators::ModelTokenizerGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ModelTokenizer::Generators::ModelTokenizerGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/model_tokenizer/model_tokenizer_generator.rb
Instance Method Summary collapse
Instance Method Details
#create_migration_file ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/generators/model_tokenizer/model_tokenizer_generator.rb', line 16 def create_migration_file if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "migration_existing.rb", "db/migrate/add_model_tokenizer_token_to_#{table_name}.rb" else migration_template "migration.rb", "db/migrate/model_tokenizer_create_#{table_name}.rb" end end |
#generate_model ⇒ Object
24 25 26 |
# File 'lib/generators/model_tokenizer/model_tokenizer_generator.rb', line 24 def generate_model invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke end |
#inject_model_tokenizer_content ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/model_tokenizer/model_tokenizer_generator.rb', line 28 def inject_model_tokenizer_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 |