Class: Gitlab::Reflections::Models::ActiveRecord
- Inherits:
-
Object
- Object
- Gitlab::Reflections::Models::ActiveRecord
- Includes:
- Singleton
- Defined in:
- lib/gitlab/reflections/models/active_record.rb
Overview
Map GitLab models to tables and back.
Instance Method Summary collapse
-
#model_name_to_table_name(model_name) ⇒ Object
Get the table name for a specific model.
- #models ⇒ Object
-
#table_name_to_model_names(table_name) ⇒ Object
Get all model names that use a specific table by looking up the db/docs catalog.
Instance Method Details
#model_name_to_table_name(model_name) ⇒ Object
Get the table name for a specific model
11 12 13 14 15 16 |
# File 'lib/gitlab/reflections/models/active_record.rb', line 11 def model_name_to_table_name(model_name) model_class = model_name.constantize model_class.table_name rescue NameError nil end |
#models ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab/reflections/models/active_record.rb', line 26 def models @models ||= begin model_classes = [] ::Gitlab::Database::Dictionary.entries.each do |entry| next unless entry.classes entry.classes.each do |class_name| model_class = class_name.constantize model_classes << model_class if included_model?(model_class) rescue NameError # Skip classes that don't exist (e.g., removed models still referenced in dictionary) next end end model_classes.uniq end end |
#table_name_to_model_names(table_name) ⇒ Object
Get all model names that use a specific table by looking up the db/docs catalog
19 20 21 22 23 24 |
# File 'lib/gitlab/reflections/models/active_record.rb', line 19 def table_name_to_model_names(table_name) entry = ::Gitlab::Database::Dictionary.any_entry(table_name) return [] unless entry entry.classes || [] end |