Class: Yes::Auth::Generators::Principals::UserRoleGenerator

Inherits:
BaseGenerator
  • Object
show all
Defined in:
lib/yes/auth/generators/principals/user_role_generator.rb

Overview

Generates the migration for the user-role join table

This generator creates a join table for the HABTM association between User and Role principals, with UUID foreign keys and cascade deletes.

Examples:

rails generate yes:auth:principals:user_role

Instance Method Summary collapse

Methods inherited from BaseGenerator

#_destination, #_migration_dir, #create, next_migration_number

Instance Method Details

#_migration_file_nameObject



27
28
29
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 27

def _migration_file_name
  "create_join_table_#{_user_table_name.singularize}_#{_role_table_name.singularize}.rb"
end

#_role_primary_keyObject



43
44
45
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 43

def _role_primary_key
  Yes::Auth::Principals::User.reflect_on_association(:roles).foreign_key
end

#_role_table_nameObject



35
36
37
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 35

def _role_table_name
  Yes::Auth::Principals::Role.table_name
end

#_source_templateObject



47
48
49
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 47

def _source_template
  'user_role.erb'
end

#_table_nameObject



22
23
24
25
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 22

def _table_name
  "#{Yes::Auth::Principals::User.reflect_on_association(:roles).table_name}_" \
    "#{Yes::Auth::Principals::Role.reflect_on_association(:users).plural_name}"
end

#_user_primary_keyObject



39
40
41
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 39

def _user_primary_key
  Yes::Auth::Principals::Role.reflect_on_association(:users).foreign_key
end

#_user_table_nameObject



31
32
33
# File 'lib/yes/auth/generators/principals/user_role_generator.rb', line 31

def _user_table_name
  Yes::Auth::Principals::User.table_name
end