Class: DependentOptionChecker::ModelLoader
- Inherits:
-
Object
- Object
- DependentOptionChecker::ModelLoader
- Defined in:
- lib/dependent_option_checker/model_loader.rb
Instance Attribute Summary collapse
-
#cache_table_attributes ⇒ Object
readonly
Returns the value of attribute cache_table_attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #application_record_classes ⇒ Object
- #application_table_models ⇒ Object
-
#initialize(config) ⇒ ModelLoader
constructor
A new instance of ModelLoader.
- #load_table_attributes ⇒ Object
Constructor Details
#initialize(config) ⇒ ModelLoader
Returns a new instance of ModelLoader.
11 12 13 |
# File 'lib/dependent_option_checker/model_loader.rb', line 11 def initialize(config) @config = config end |
Instance Attribute Details
#cache_table_attributes ⇒ Object (readonly)
Returns the value of attribute cache_table_attributes.
9 10 11 |
# File 'lib/dependent_option_checker/model_loader.rb', line 9 def cache_table_attributes @cache_table_attributes end |
Class Method Details
.load_files! ⇒ Object
5 6 7 |
# File 'lib/dependent_option_checker/model_loader.rb', line 5 def self.load_files! Rails.autoloaders.main.eager_load_dir(Rails.root.join('app', 'models')) unless Rails.env.production? end |
Instance Method Details
#application_record_classes ⇒ Object
15 16 17 |
# File 'lib/dependent_option_checker/model_loader.rb', line 15 def application_record_classes @application_record_classes ||= ::ApplicationRecord.descendants.filter(&:base_class?) end |
#application_table_models ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dependent_option_checker/model_loader.rb', line 19 def application_table_models @application_table_models ||= application_record_classes.reject do |klass| next if @config.nil? @config.ignored_tables.include?(klass.table_name) end end |
#load_table_attributes ⇒ Object
27 28 29 30 31 |
# File 'lib/dependent_option_checker/model_loader.rb', line 27 def load_table_attributes @cache_table_attributes = application_table_models.each_with_object({}) do |klass, acc| acc[klass.table_name] = klass.attribute_names end end |