Class: Vindi::Generators::SyncGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/vindi/sync_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



15
16
17
# File 'lib/generators/vindi/sync_generator.rb', line 15

def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#create_migration_fileObject



19
20
21
# File 'lib/generators/vindi/sync_generator.rb', line 19

def create_migration_file
  migration_template "migration.rb", "db/migrate/add_vindi_fields_to_#{table_name}.rb"
end

#inject_concern_into_modelObject



23
24
25
26
27
28
29
30
31
# File 'lib/generators/vindi/sync_generator.rb', line 23

def inject_concern_into_model
  model_path = File.join("app/models", "#{file_path}.rb")
  
  if File.exist?(model_path)
    inject_into_class(model_path, class_name, "  include Vindi::Synchronizable\n")
  else
    say_status("warning", "Model file #{model_path} not found. Please add 'include Vindi::Synchronizable' manually.", :yellow)
  end
end