Class: Yes::Core::Utils::AggregateShortcuts
- Inherits:
-
Object
- Object
- Yes::Core::Utils::AggregateShortcuts
- Defined in:
- lib/yes/core/utils/aggregate_shortcuts.rb
Overview
Provides convenient shortcuts for accessing aggregate classes in Rails console.
Class Method Summary collapse
-
.display(filter = nil) ⇒ Object
Display shortcuts in a formatted table.
-
.list(filter = nil) ⇒ Hash
List all available shortcuts.
-
.load! ⇒ Object
Load aggregate shortcuts in Rails console.
Class Method Details
.display(filter = nil) ⇒ Object
Display shortcuts in a formatted table.
Writes directly to STDOUT (via Kernel#puts) rather than the Rails logger so the output is readable in any environment — Rails consoles in production typically configure structured / JSON loggers that would otherwise wrap each line in a JSON envelope.
rubocop:disable Rails/Output
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yes/core/utils/aggregate_shortcuts.rb', line 50 def display(filter = nil) shortcuts = list(filter) if shortcuts.empty? puts "No shortcuts found#{" for '#{filter}'" if filter}." return end max_shortcut_length = shortcuts.keys.map(&:length).max separator = '=' * (max_shortcut_length + 70) puts "\nAvailable Aggregate Shortcuts:" puts separator shortcuts.sort.each do |shortcut, full_path| puts "#{shortcut.ljust(max_shortcut_length)} → #{full_path}" end puts separator puts "\nUsage: #{shortcuts.keys.first}.new(id)" end |
.list(filter = nil) ⇒ Hash
List all available shortcuts
35 36 37 38 39 |
# File 'lib/yes/core/utils/aggregate_shortcuts.rb', line 35 def list(filter = nil) results = @shortcuts || {} results = results.select { |shortcut, _| shortcut.start_with?("#{filter}::") } if filter results end |
.load! ⇒ Object
Load aggregate shortcuts in Rails console. Creates fresh shortcut modules (e.g. TF) and assigns aggregate classes as constants on them. Shortcut modules are NOT aliases of the real context modules, so shortcut constants cannot collide with the aggregates’ own namespace modules.
20 21 22 23 24 25 26 27 |
# File 'lib/yes/core/utils/aggregate_shortcuts.rb', line 20 def load! return unless Yes::Core.configuration.aggregate_shortcuts load_overrides discover_aggregates create_shortcuts define_helper_method end |