Module: Rodauth::Tools::ConsoleHelpers
- Defined in:
- lib/rodauth/tools/console_helpers.rb
Overview
Class Method Summary collapse
-
.extended(base) ⇒ Module
Class method to extend a context with helpers and set up rodauth method.
Instance Method Summary collapse
-
#config ⇒ Object
Get discovered table configuration.
-
#create_tables! ⇒ Object
Create missing tables immediately.
-
#db ⇒ Object
Access database connection.
-
#help ⇒ Object
Show help message.
-
#missing ⇒ Object
Get missing tables.
-
#rodauth ⇒ Object
Get or create a Rodauth instance.
-
#show_config ⇒ Object
Pretty-print table configuration.
-
#show_migration ⇒ Object
Display generated migration code.
-
#show_missing ⇒ Object
Pretty-print missing tables.
-
#show_status ⇒ Object
Pretty-print table status.
-
#status ⇒ Object
Get detailed status for each table.
-
#tables ⇒ Object
List all required table names.
Class Method Details
.extended(base) ⇒ Module
Class method to extend a context with helpers and set up rodauth method
152 153 154 155 |
# File 'lib/rodauth/tools/console_helpers.rb', line 152 def self.extended(base) puts "\nā Rodauth console helpers loaded!" base.help if base.respond_to?(:help) end |
Instance Method Details
#config ⇒ Object
Get discovered table configuration
25 26 27 |
# File 'lib/rodauth/tools/console_helpers.rb', line 25 def config rodauth.table_configuration end |
#create_tables! ⇒ Object
Create missing tables immediately
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rodauth/tools/console_helpers.rb', line 86 def create_tables! puts "\n=== Creating Missing Tables ===" missing_list = missing if missing_list.empty? puts 'ā All tables already exist!' return end generator = Rodauth::SequelGenerator.new(missing_list, rodauth) generator.execute_creates(db) puts "ā Created #{missing_list.size} table(s)" show_status nil end |
#db ⇒ Object
Access database connection
45 46 47 |
# File 'lib/rodauth/tools/console_helpers.rb', line 45 def db rodauth.db if rodauth.respond_to?(:db) end |
#help ⇒ Object
Show help message
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rodauth/tools/console_helpers.rb', line 116 def help puts <<~HELP š Rodauth Console Helpers ============================ rodauth # Get Rodauth instance config # Get discovered table configuration missing # Get missing tables tables # List all required table names status # Get detailed status for each table db # Access Sequel database connection show_config # Pretty-print table configuration show_missing # Pretty-print missing tables show_status # Pretty-print table status create_tables! # Create all missing tables show_migration # Display generated migration code help # Show this help Examples: --------- config.keys # See all table methods missing.size # How many tables are missing? rodauth.table_exists?(:accounts) # Check specific table db.tables # See what's in the database HELP nil end |
#missing ⇒ Object
Get missing tables
30 31 32 |
# File 'lib/rodauth/tools/console_helpers.rb', line 30 def missing rodauth.missing_tables end |
#rodauth ⇒ Object
Get or create a Rodauth instance
Override this method in your console script to provide the actual instance
20 21 22 |
# File 'lib/rodauth/tools/console_helpers.rb', line 20 def rodauth @rodauth ||= raise NotImplementedError, 'You must define a `rodauth` method that returns a Rodauth instance' end |
#show_config ⇒ Object
Pretty-print table configuration
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rodauth/tools/console_helpers.rb', line 50 def show_config puts "\n=== Table Configuration ===" config.each do |method, info| puts "\n#{method}:" puts " Table: #{info[:name]}" puts " Feature: #{info[:feature]}" puts " Type: #{info[:structure][:type]}" puts " Exists: #{rodauth.table_exists?(info[:name])}" end nil end |
#show_migration ⇒ Object
Display generated migration code
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rodauth/tools/console_helpers.rb', line 102 def show_migration puts "\n=== Generated Migration ===" missing_list = missing if missing_list.empty? puts 'ā All tables exist - no migration needed' return end generator = Rodauth::SequelGenerator.new(missing_list, rodauth) puts generator.generate_migration nil end |
#show_missing ⇒ Object
Pretty-print missing tables
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rodauth/tools/console_helpers.rb', line 63 def show_missing puts "\n=== Missing Tables ===" if missing.empty? puts 'ā All tables exist!' else missing.each do |info| puts "ā #{info[:table]} (feature: #{info[:feature]})" end end nil end |
#show_status ⇒ Object
Pretty-print table status
76 77 78 79 80 81 82 83 |
# File 'lib/rodauth/tools/console_helpers.rb', line 76 def show_status puts "\n=== Table Status ===" status.each do |info| marker = info[:exists] ? 'ā' : 'ā' puts "#{marker} #{info[:table].to_s.ljust(30)} (#{info[:feature]})" end nil end |
#status ⇒ Object
Get detailed status for each table
40 41 42 |
# File 'lib/rodauth/tools/console_helpers.rb', line 40 def status rodauth.table_status end |
#tables ⇒ Object
List all required table names
35 36 37 |
# File 'lib/rodauth/tools/console_helpers.rb', line 35 def tables rodauth.list_all_required_tables end |