| 141 | | $LOAD_PATH.unshift( File.join(Merb.root , '/app/models') ) |
|---|
| 142 | | $LOAD_PATH.unshift( File.join(Merb.root , '/app/controllers') ) |
|---|
| | 141 | |
|---|
| | 142 | #Magic Class Loading => Not failing on missing parent due to alphabetical loading |
|---|
| | 143 | # Does a reverse alphaebetical search if classes failed in first pass |
|---|
| | 144 | # Will continue to reverse the list of failures until the size does change between |
|---|
| | 145 | # two passes |
|---|
| | 146 | |
|---|
| | 147 | orphaned_paths = [] |
|---|
| | 148 | $LOAD_PATH.unshift( File.join(Merb.root,'/app/models') ) |
|---|
| | 149 | $LOAD_PATH.unshift( File.join(Merb.root,'/app/controllers') ) |
|---|
| | 170 | |
|---|
| | 171 | |
|---|
| | 172 | def load_classes_with_requirements(orphaned_paths) |
|---|
| | 173 | |
|---|
| | 174 | #Make the list unique |
|---|
| | 175 | orphaned_paths.uniq! |
|---|
| | 176 | |
|---|
| | 177 | while orphaned_paths.size > 0 |
|---|
| | 178 | #Take the size for comparison later |
|---|
| | 179 | size_at_start = orphaned_paths.size |
|---|
| | 180 | |
|---|
| | 181 | fail_list = [] #List of failures |
|---|
| | 182 | |
|---|
| | 183 | # Try to load each path again, this time the order is reversed |
|---|
| | 184 | (orphaned_paths).each do |m| |
|---|
| | 185 | # Remove the path from the list |
|---|
| | 186 | orphaned_paths.delete(m) |
|---|
| | 187 | begin |
|---|
| | 188 | require m |
|---|
| | 189 | rescue NameError |
|---|
| | 190 | # Add it back on if it failed to load due to NameError |
|---|
| | 191 | fail_list.push(m) |
|---|
| | 192 | end |
|---|
| | 193 | end |
|---|
| | 194 | |
|---|
| | 195 | orphaned_paths.concat(fail_list) |
|---|
| | 196 | |
|---|
| | 197 | # Stop processing if everything loaded (size == 0) or if the size didn't change |
|---|
| | 198 | # (ie something couldn't be loaded) |
|---|
| | 199 | break if(orphaned_paths.size == size_at_start || orphaned_paths.size == 0) |
|---|
| | 200 | end |
|---|
| | 201 | |
|---|
| | 202 | return orphaned_paths |
|---|
| | 203 | end |
|---|
| | 204 | |
|---|