Class: RailsKindeditor::MigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/rails_kindeditor/migration/migration_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/generators/rails_kindeditor/migration/migration_generator.rb', line 22

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#copy_filesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/rails_kindeditor/migration/migration_generator.rb', line 8

def copy_files
  orm = options[:orm].to_s
  orm = "active_record" unless %w{active_record mongoid}.include?(orm)
  %w(asset file flash image media).each do |file|
    copy_model(orm, file)
  end
  if Rails.version < '4.0.0' && Rails.version >= '3.0.0' # insert code for rails3
    insert_into_file "app/models/kindeditor/asset.rb", "  attr_accessible :asset\n", :after => "before_save :update_asset_attributes\n"
  end
  if orm == "active_record"
    migration_template "migration/migration.rb", "db/migrate/create_kindeditor_assets.rb"
  end
end