Class: Nullalign::Models

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

Constant Summary collapse

MODEL_DIRECTORY_REGEXP =
/models/
IGNORE_DIRECTORY_REGEXP =
/activestorage-\S*\/app\/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/nullalign/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/nullalign/models.rb', line 8

def load_path
  @load_path
end

Instance Method Details

#allObject



26
27
28
# File 'lib/nullalign/models.rb', line 26

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

#dirsObject



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

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

#preload_allObject



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

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