Class: Yes::Auth::Generators::BaseGenerator Abstract
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Yes::Auth::Generators::BaseGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/yes/auth/generators/base_generator.rb
Overview
This class is abstract.
Subclass and implement #_table_name and #_source_template
Base class for auth principal migration generators
Provides shared migration generation logic including timestamp calculation, existence checking, and template rendering.
Direct Known Subclasses
Principals::ReadResourceAccessGenerator, Principals::RoleGenerator, Principals::UserGenerator, Principals::UserRoleGenerator, Principals::WriteResourceAccessGenerator
Class Method Summary collapse
-
.next_migration_number(migrations_root) ⇒ String
Calculates the next migration number based on existing migrations.
Instance Method Summary collapse
- #_destination ⇒ Object
- #_migration_dir ⇒ Object
- #_migration_file_name ⇒ Object
- #_source_template ⇒ Object
- #_table_name ⇒ Object
- #create ⇒ Object
Class Method Details
.next_migration_number(migrations_root) ⇒ String
Calculates the next migration number based on existing migrations
23 24 25 26 27 28 29 30 |
# File 'lib/yes/auth/generators/base_generator.rb', line 23 def self.next_migration_number(migrations_root) paths = Dir["#{migrations_root}/*.rb"].map do |path| File.basename(path) end = paths.map { |name| name.split('_').first } latest = .max || '0' [Time.now.utc.strftime('%Y%m%d%H%M%S'), format('%.14d', latest.next)].max end |
Instance Method Details
#_destination ⇒ Object
46 47 48 |
# File 'lib/yes/auth/generators/base_generator.rb', line 46 def _destination "#{_migration_dir}/#{_migration_file_name}" end |
#_migration_dir ⇒ Object
54 55 56 |
# File 'lib/yes/auth/generators/base_generator.rb', line 54 def _migration_dir 'db/migrate' end |
#_migration_file_name ⇒ Object
50 51 52 |
# File 'lib/yes/auth/generators/base_generator.rb', line 50 def _migration_file_name "create_#{_table_name.singularize}.rb" end |
#_source_template ⇒ Object
42 43 44 |
# File 'lib/yes/auth/generators/base_generator.rb', line 42 def _source_template raise NotImplementedError end |
#_table_name ⇒ Object
38 39 40 |
# File 'lib/yes/auth/generators/base_generator.rb', line 38 def _table_name raise NotImplementedError end |
#create ⇒ Object
32 33 34 35 36 |
# File 'lib/yes/auth/generators/base_generator.rb', line 32 def create raise "Migration already exists in #{_migration_dir}" if self.class.migration_exists?(_migration_dir, _migration_file_name) migration_template(_source_template, _destination) end |