Class: Cabalist::ClassifierGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Cabalist::ClassifierGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/cabalist/classifier/classifier_generator.rb
Overview
A Rails-specific generator which enables a class to use Cabalist methods.
This generator creates a migration to add autoclassified_at attribute to a chosen ActiveRecord model. It also prompts the user whether the resulting classifier should be exposed through the GUI.
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Get the next available number for a database migration.
Instance Method Summary collapse
-
#add_to_gui_if_necessary ⇒ Object
Prompt whether to expose the classifier through GUI.
-
#create_migration ⇒ Object
Create a database migration adding autoclassified_at attribute.
Class Method Details
.next_migration_number(dirname) ⇒ Object
Get the next available number for a database migration
22 23 24 |
# File 'lib/generators/cabalist/classifier/classifier_generator.rb', line 22 def self.next_migration_number(dirname) Time.now.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#add_to_gui_if_necessary ⇒ Object
Prompt whether to expose the classifier through GUI
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/cabalist/classifier/classifier_generator.rb', line 33 def add_to_gui_if_necessary add_to_gui = '' until %w(y Y n N).include?(add_to_gui) add_to_gui = ask "Would you like to have access to this model through GUI dashboard? (Y/n) " end if %w(Y y).include?(add_to_gui) inject_into_file "config/initializers/cabalist.rb", "\n config.frontend_classes << #{name}", :before => "\nend" end end |
#create_migration ⇒ Object
Create a database migration adding autoclassified_at attribute.
27 28 29 30 |
# File 'lib/generators/cabalist/classifier/classifier_generator.rb', line 27 def create_migration migration_template("migrations/add_cabalist.rb.erb", "db/migrate/add_cabalist_to_#{name.tableize}.rb") end |