Class: Nullalign::Models
- Inherits:
-
Object
- Object
- Nullalign::Models
- Defined in:
- lib/nullalign/models.rb
Constant Summary collapse
- MODEL_DIRECTORY_REGEXP =
/models/
- IGNORE_DIRECTORY_REGEXP =
/activestorage-\S*\/app\/models/
Instance Attribute Summary collapse
-
#load_path ⇒ Object
readonly
Returns the value of attribute load_path.
Instance Method Summary collapse
- #all ⇒ Object
- #dirs ⇒ Object
-
#initialize(load_path) ⇒ Models
constructor
A new instance of Models.
- #preload_all ⇒ Object
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_path ⇒ Object (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
#all ⇒ Object
26 27 28 |
# File 'lib/nullalign/models.rb', line 26 def all ActiveRecord::Base.descendants.sort_by(&:name) end |
#dirs ⇒ Object
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_all ⇒ Object
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 |