Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RubyMotion app files load order: how to load lib files before other files?

Tags:

rubymotion

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?

like image 604
joelparkerhenderson Avatar asked Nov 10 '22 03:11

joelparkerhenderson


1 Answers

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.

like image 52
Jamon Holmgren Avatar answered Jan 04 '23 03:01

Jamon Holmgren