# File lib/generators/shared_utilities/migration_generator.rb, line 68 def primary_key_string key_string = options[:primary_key_type] || "bigserial" ", id: :#{key_string}" if key_string end
class SharedUtilities::MigrationGenerator
Public Class Methods
new(args, *options)
click to toggle source
Calls superclass method
# File lib/generators/shared_utilities/migration_generator.rb, line 16 def initialize(args, *options) raise StandardError, "Only 'authentication' model is currently implemented" if args.first != "authentication" super end
Public Instance Methods
copy_migration()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 25 def copy_migration if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) migration_template "migration_existing.rb", "#{migration_path}/update_authentications_on_#{table_name}.rb", migration_version: migration_version else migration_template "migration.rb", "#{migration_path}/create_#{table_name}.rb", migration_version: migration_version end end
inet?()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 51 def inet? postgresql? end
ip_column()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 46 def ip_column # Padded with spaces so it aligns nicely with the rest of the columns. "%-8s" % (inet? ? "inet" : "string") end
manifest()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 21 def manifest copy_migration end
migration_data()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 33 def migration_data <<RUBY ## Required # t.references "resource", :polymorphic => true, :index => true # t.string :name # t.string :authtype # t.string :status # t.string :status_details # t.#{ip_column} :tenant_id # t.timestamps RUBY end
migration_version()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 73 def migration_version if rails5? "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end
postgresql?()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 59 def postgresql? config = ActiveRecord::Base.configurations[Rails.env] config && config['adapter'] == 'postgresql' end
primary_key_string()
click to toggle source
primary_key_type()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 64 def primary_key_type primary_key_string if rails5? end
rails5?()
click to toggle source
# File lib/generators/shared_utilities/migration_generator.rb, line 55 def rails5? Rails.version.start_with? '5' end