install_generator.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. # taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
  2. require "rails/generators"
  3. require "rails/generators/migration"
  4. require "active_record"
  5. require "rails/generators/active_record"
  6. module Blazer
  7. module Generators
  8. class InstallGenerator < Rails::Generators::Base
  9. include Rails::Generators::Migration
  10. source_root File.expand_path("../templates", __FILE__)
  11. # Implement the required interface for Rails::Generators::Migration.
  12. def self.next_migration_number(dirname) #:nodoc:
  13. next_migration_number = current_migration_number(dirname) + 1
  14. if ActiveRecord::Base.timestamped_migrations
  15. [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
  16. else
  17. "%.3d" % next_migration_number
  18. end
  19. end
  20. def copy_migration
  21. migration_template "install.rb", "db/migrate/install_blazer.rb"
  22. end
  23. def copy_config
  24. template "config.yml", "config/blazer.yml"
  25. end
  26. end
  27. end
  28. end