Module: DatabaseConsistency::Helper

Defined in:
lib/database_consistency/helper.rb

Overview

The module contains helper methods

Class Method Summary collapse

Class Method Details

.find_field(model, attribute) ⇒ Object

Find a database field with name equals to attribute



17
18
19
# File 'lib/database_consistency/helper.rb', line 17

def find_field(model, attribute)
  model.columns.select.find { |field| field.name == attribute }
end

.load_environment!Object

Loads all models



12
13
14
# File 'lib/database_consistency/helper.rb', line 12

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

.message(model, column, template = nil) ⇒ String

Returns:

  • (String)


22
23
24
25
26
# File 'lib/database_consistency/helper.rb', line 22

def message(model, column, template = nil)
  str = "column #{column.name} of table #{model.table_name}"
  str += " #{template}" if template
  str
end

.modelsObject

Returns list of models to check



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

def models
  ActiveRecord::Base.descendants.select { |model| model.validators.any? }
end