Module: DatabaseConsistency::Helper
- Defined in:
- lib/database_consistency/helper.rb
Overview
The module contains helper methods
Class Method Summary collapse
- .check_inclusion?(array, element) ⇒ Boolean
-
.load_environment! ⇒ Object
Loads all models.
-
.models ⇒ Object
Returns list of models to check.
-
.parent_models ⇒ Object
Return list of not inherited models.
Class Method Details
.check_inclusion?(array, element) ⇒ Boolean
26 27 28 |
# File 'lib/database_consistency/helper.rb', line 26 def check_inclusion?(array, element) array.include?(element.to_s) || array.include?(element.to_sym) end |
.load_environment! ⇒ Object
Loads all models
21 22 23 |
# File 'lib/database_consistency/helper.rb', line 21 def load_environment! Rails.application.eager_load! if defined?(Rails) end |
.models ⇒ Object
Returns list of models to check
9 10 11 |
# File 'lib/database_consistency/helper.rb', line 9 def models ActiveRecord::Base.descendants.delete_if(&:abstract_class?) end |
.parent_models ⇒ Object
Return list of not inherited models
14 15 16 17 18 |
# File 'lib/database_consistency/helper.rb', line 14 def parent_models models.group_by(&:table_name).each_value.map do |models| models.min_by { |model| models.include?(model.superclass) ? 1 : 0 } end end |