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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yes/core/utils/aggregate_shortcuts.rb', line 43 def display(filter = nil) shortcuts = list(filter) if shortcuts.empty? Rails.logger.debug { "No shortcuts found#{" for '#{filter}'" if filter}." } return end max_shortcut_length = shortcuts.keys.map(&:length).max Rails.logger.debug "\nAvailable Aggregate Shortcuts:" Rails.logger.debug '=' * (max_shortcut_length + 70) shortcuts.sort.each do |shortcut, full_path| Rails.logger.debug "#{shortcut.ljust(max_shortcut_length)} → #{full_path}" end Rails.logger.debug '=' * (max_shortcut_length + 70) Rails.logger.debug { "\nUsage: #{shortcuts.keys.first}.new(id)" } if shortcuts.any? 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 |