Class: ConsistencyFail::Models
- Inherits:
-
Object
- Object
- ConsistencyFail::Models
- Defined in:
- lib/consistency_fail/models.rb
Constant Summary collapse
- MODEL_DIRECTORY_REGEXP =
/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/consistency_fail/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/consistency_fail/models.rb', line 8 def load_path @load_path end |
Instance Method Details
#all ⇒ Object
27 28 29 |
# File 'lib/consistency_fail/models.rb', line 27 def all ActiveRecord::Base.send(:descendants).sort_by(&:name) end |
#dirs ⇒ Object
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_all ⇒ Object
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 |