Module: SchemaSherlock::ModelLoader

Defined in:
lib/schema_sherlock/model_loader.rb

Class Method Summary collapse

Class Method Details

.all_modelsObject



4
5
6
7
8
9
10
11
# File 'lib/schema_sherlock/model_loader.rb', line 4

def all_models
  ensure_rails_loaded!
  load_application_models

  ActiveRecord::Base.descendants.select do |klass|
    includable_model?(klass)
  end
end

.find_model(name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/schema_sherlock/model_loader.rb', line 13

def find_model(name)
  ensure_rails_loaded!

  klass = name.safe_constantize || name.camelize.safe_constantize

  unless klass
    raise SchemaSherlock::Error, "Could not find model: #{name}"
  end

  unless klass < ActiveRecord::Base
    raise SchemaSherlock::Error, "#{name} is not an ActiveRecord model"
  end

  unless klass.table_exists?
    raise SchemaSherlock::Error, "Table for #{name} does not exist"
  end

  klass
end