I have a RubyMotion project that needs to load certain directories and files earlier than others.
I want to load the /lib
directory files before the /app
directory files.
Research turned up many ways to adjust the load order, but no definitive answer IMHO.
Here's what I've found thus far.
To set the app files load order, use the Rakefile App setup block:
Motion::Project::App.setup do |app|
# ... put your code here
end
To choose directories:
app.files =
Dir.glob('./lib/**/*.rb') |
Dir.glob('./app/**/*.rb')
To use dependencies:
app.files_dependencies \
'app/child.rb' => 'lib/parent.rb'
To add files to the start of the load order, before gems:
app.files.unshift \
Dir.glob('./lib/**/*.rb')
To utilize the BubbleWrap gem:
BW.require './lib/**/*.rb'
To utilize the Motion Dependencies gem:
app.files =
Dir.glob('./lib/**/*.rb') |
Dir.glob('./app/**/*.rb')
app.files_dependencies Motion::Dependencies.find_dependencies(app.files)
To load vendor bundle files first, then library files, then everything else -- this seems like the best solution so far to me.
app.files = (
app.files.select{|f| f =~ %r(/vendor/bundle/) } +
app.files.select{|f| f =~ %r(/lib/) } +
app.files
).uniq
Is there a definitive way that's better?
Old question, but my opinion is that your final solution looks the nicest. I also like the DBT gem, but I usually only use it on gems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With