Module: DatabaseConsistency::Helper

Defined in:
lib/database_consistency/helper.rb

Overview

The module contains helper methods

Class Method Summary collapse

Class Method Details

.check_inclusion?(array, element) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/database_consistency/helper.rb', line 31

def check_inclusion?(array, element)
  array.include?(element.to_s) || array.include?(element.to_sym)
end

.load_environment! ⇒ Object

Loads all models



26
27
28
# File 'lib/database_consistency/helper.rb', line 26

def load_environment!
  Rails.application.eager_load! if defined?(Rails)
end

.models ⇒ Object

Returns list of models to check



14
15
16
# File 'lib/database_consistency/helper.rb', line 14

def models
  ActiveRecord::Base.descendants.delete_if(&:abstract_class?)
end

.parent_models ⇒ Object

Return list of not inherited models



19
20
21
22
23
# File 'lib/database_consistency/helper.rb', line 19

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

.welcome_message! ⇒ Object



8
9
10
11
# File 'lib/database_consistency/helper.rb', line 8

def welcome_message!
  puts 'Thank you for using the gem. Any contribution is welcome https://github.com/djezzzl/database_consistency!'
  puts '(c) Evgeniy Demin <[email protected]>'
end