Module: SupportTableData::Tasks::Utils
- Defined in:
- lib/tasks/utils.rb
Class Method Summary collapse
-
.eager_load! ⇒ Object
Helper for eager loading a Rails application.
- .model_file_path(klass) ⇒ Object
-
.support_table_sources ⇒ Array<SupportTableData::Documentation::SourceFile>
Return a hash mapping all models that include SupportTableData to their source file paths.
Class Method Details
.eager_load! ⇒ Object
Helper for eager loading a Rails application.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tasks/utils.rb', line 8 def eager_load! return unless defined?(Rails.application.config.eager_load) return if Rails.application.config.eager_load if defined?(Rails.application.eager_load!) Rails.application.eager_load! elsif defined?(Rails.autoloaders.zeitwerk_enabled?) && Rails.autoloaders.zeitwerk_enabled? Rails.autoloaders.each(&:eager_load) else raise "Failed to eager load application." end end |
.model_file_path(klass) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tasks/utils.rb', line 46 def model_file_path(klass) file_path = "#{klass.name.underscore}.rb" model_path = nil Rails.application.config.paths["app/models"].each do |path_prefix| path = Pathname.new(path_prefix.to_s).join(file_path) if path&.file? && path.readable? model_path = path break end end model_path end |
.support_table_sources ⇒ Array<SupportTableData::Documentation::SourceFile>
Return a hash mapping all models that include SupportTableData to their source file paths.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tasks/utils.rb', line 24 def support_table_sources sources = [] ActiveRecord::Base.descendants.each do |klass| next unless klass.included_modules.include?(SupportTableData) begin next if klass.instance_names.empty? rescue NoMethodError # Skip models where instance_names is not properly initialized next end file_path = SupportTableData::Tasks::Utils.model_file_path(klass) next unless file_path&.file? && file_path.readable? sources << Documentation::SourceFile.new(klass, file_path) end sources end |