Class: ActiveRecord::Generators::AASMGenerator

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

Instance Method Summary collapse

Methods included from AASM::Generators::OrmHelpers

#model_contents

Instance Method Details

#copy_aasm_migrationObject


13
14
15
16
17
18
19
20
21
# File 'lib/generators/active_record/aasm_generator.rb', line 13

def copy_aasm_migration
  if column_exists?
    puts "Both model and column exists"
  elsif model_exists?
    migration_template "migration_existing.rb", "db/migrate/add_#{column_name}_to_#{table_name}.rb"
  else
    migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
  end
end

#generate_modelObject


23
24
25
# File 'lib/generators/active_record/aasm_generator.rb', line 23

def generate_model
  invoke "active_record:model", [name], migration: false unless model_exists?
end

#inject_aasm_contentObject


27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/active_record/aasm_generator.rb', line 27

def inject_aasm_content
  content = model_contents

  class_path = if namespaced?
                 class_name.to_s.split("::")
               else
                 [class_name]
               end
  inject_into_class(model_path, class_path.last, content) if model_exists?
end