require 'rails/generators/active_record' module Radmin module Generators class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root File.expand_path("../templates", __FILE__) def copy_migrations mig_dir = 'db/migrate' Dir[File.join(self.class.source_root,'migrations','*.rb')].sort!.each do |m| mig_name = File.basename(m).sub(/\.rb$/, '') new_name = mig_name.gsub(/^[0-9].*?_/, '') unless self.class.migration_exists?(mig_dir, new_name) mig_number = ActiveRecord::Generators::Base.next_migration_number(mig_dir) destination = File.join(mig_dir, "#{mig_number}_#{new_name}.rb") template("migrations/#{mig_name}.rb", destination) end end end def copy_assets directory 'assets', 'public', :recursive => true end def copy_authorization_file template "authorization_rules.rb", "config/authorization_rules.rb" end end end end