Sha256: 078e2e7f4d1d13c6b973562fac476de4559cc7622a5dc7121a3d59b5fafc5bdc
Contents?: true
Size: 1.75 KB
Versions: 10
Compression:
Stored size: 1.75 KB
Contents
module Cloudfuji module Generators class AuthMigrationGenerator < Rails::Generators::NamedBase def create_auth_migration_file fields_to_add = [] new_resource = class_name.constantize.new fields_to_add << "ido_id" if not new_resource.respond_to?(:ido_id) fields_to_add << "first_name" if not new_resource.respond_to?(:first_name) fields_to_add << "last_name" if not new_resource.respond_to?(:last_name) fields_to_add << "email" if not new_resource.respond_to?(:email) fields_to_add << "locale" if not new_resource.respond_to?(:locale) fields_to_add << "timezone" if not new_resource.respond_to?(:timezone) attr_accessor_string = fields_to_add.collect { |field| ":"+field}.join(", ") inject_into_class "app/models/#{class_name.underscore}.rb", class_name do <<-EOF attr_accessor #{attr_accessor_string}\n def cloudfuji_extra_attributes(extra_attributes) self.first_name = extra_attributes["first_name"].to_s self.last_name = extra_attributes["last_name"].to_s self.email = extra_attributes["email"] self.locale = extra_attributes["locale"] self.timezone = extra_attributes["timezone"] end EOF end gem("devise_cloudfuji_authenticatable") generate("migration", "AddCloudfujiFieldsTo#{class_name}", *fields_to_add.collect { |field| field + ":string"}) generate("migration", "AddIndexForIdoIdTo#{class_name}") Dir["db/migrate/*add_index_for_ido_id_to*"].each do |file| inject_into_file file, :after => "class AddIndexForIdoIdToUser < ActiveRecord::Migration\n def change\n" do " add_index :#{plural_name}, :ido_id\n" end end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems