Sha256: 9cdab5c1552ed2432679c02fdba31a3acf56a742a79be5afe59ef6d8aa2acf39
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
require 'rails/generators/migration' class DeviseDateRestrictableGenerator < Rails::Generators::Base include Rails::Generators::Migration def self.source_root @_devise_source_root ||= File.expand_path( '../templates', __FILE__ ) end 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 class_option :model, type: :string, default: 'User' desc "Generates a migration to add required fields to devise account model." def invoke_migration model_name = options['model'] @model_name = model_name.camelize.singularize if columns_exist? say "* Date restrictable columns already seem to exist on @{model_name}" else migration_template 'migration.rb', "db/migrate/devise_add_#{model_name.downcase}_date_restriction_fields.rb" end puts "\n\nMake sure to add :date_restrictable to the devise line of your #{@model_name} model file!\n\n" end protected def columns_exist? @model_name.constantize.column_names.include?( 'valid_from' ) and @model_name.constantize.column_names.include?( 'valid_until' ) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
devise_date_restrictable-1.0.0 | lib/generators/devise_date_restrictable/devise_date_restrictable_generator.rb |