Sha256: 7eb14f285a6dd883464ec52797581b76a65cd48ab105d5b874704cbb3e8d6d4e

Contents?: true

Size: 967 Bytes

Versions: 8

Compression:

Stored size: 967 Bytes

Contents

puts "Loading ThecoreAuthCommons seeds"

# Needing this since in the rake task is not aeger loaded
Zeitwerk::Loader.eager_load_all

email = "admin@#{ENV["BASE_DOMAIN"].presence || "example.com"}"
psswd = ENV["ADMIN_PASSWORD"].presence || "changeme"

unless User.where(admin: true).exists?
    u = User.find_or_initialize_by(email: email)
    u.password = u.password_confirmation = psswd
    u.admin = true
    u.save(validate: false)
end

@values = {
    predicates: %i[can cannot],
    actions: %i[manage create read update destroy],
    targets: ApplicationRecord.subclasses.map {|d| d.to_s.underscore}.to_a.unshift("all")
}

def fill table
    model = table.to_s.classify.constantize
    model.reset_column_information
    puts " - Filling table #{table} with #{@values[table].count} elements:"
    @values[table].each do |name|
        puts "   - Name: #{name}"
        model.find_or_create_by name: name
    end
end

fill :predicates
fill :actions
fill :targets

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thecore_auth_commons-3.2.3 db/seeds.rb
thecore_auth_commons-3.2.2 db/seeds.rb
thecore_auth_commons-3.2.1 db/seeds.rb
thecore_auth_commons-3.1.7 db/seeds.rb
thecore_auth_commons-3.1.5 db/seeds.rb
thecore_auth_commons-3.1.4 db/seeds.rb
thecore_auth_commons-3.1.3 db/seeds.rb
thecore_auth_commons-3.1.2 db/seeds.rb