Class: ConsistencyFail::Models

Inherits:
Object
  • Object
show all
Defined in:
lib/consistency_fail/models.rb

Constant Summary collapse

MODEL_DIRECTORY_REGEXP =
/models/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_path) ⇒ Models

Returns a new instance of Models.



10
11
12
# File 'lib/consistency_fail/models.rb', line 10

def initialize(load_path)
  @load_path = load_path
end

Instance Attribute Details

#load_pathObject (readonly)

Returns the value of attribute load_path.



8
9
10
# File 'lib/consistency_fail/models.rb', line 8

def load_path
  @load_path
end

Instance Method Details

#allObject



27
28
29
# File 'lib/consistency_fail/models.rb', line 27

def all
  ActiveRecord::Base.send(:descendants).sort_by(&:name)
end

#dirsObject



14
15
16
# File 'lib/consistency_fail/models.rb', line 14

def dirs
  load_path.select { |lp| MODEL_DIRECTORY_REGEXP =~ lp.to_s }
end

#preload_allObject



18
19
20
21
22
23
24
25
# File 'lib/consistency_fail/models.rb', line 18

def preload_all
  self.dirs.each do |d|
    ruby_files = Dir.glob(File.join(d, "**", "*.rb")).sort
    ruby_files.each do |model_filename|
      Kernel.require model_filename
    end
  end
end