Class: Filch::ModelFind
- Inherits:
-
Object
- Object
- Filch::ModelFind
- Defined in:
- lib/filch/model_find.rb
Overview
return a model from a string representing the model.name or return the first model
Class Method Summary collapse
Class Method Details
.all_models ⇒ Object
11 12 13 14 15 |
# File 'lib/filch/model_find.rb', line 11 def self.all_models Rails.application.eager_load! ActiveRecord::Base.descendants ApplicationRecord.descendants end |
.find(find_model = nil) ⇒ Object
5 6 7 8 9 |
# File 'lib/filch/model_find.rb', line 5 def self.find(find_model = nil) models = all_models found_model = models.select { |model| model.name == find_model }.first found_model || models.first if models.any? || ApplicationRecord.new end |