Last Updated: February 25, 2016
·
1.583K
· jamesotron

Using BubbleWrap.require

When I implemented the code loading hooks for BubbleWrap I went to a lot of trouble to use a bunch of different heuristics to figure out the project's root directory. It seems I may have over engineered the solutions, since I keep seeing idioms like this in the wild:

Dir.glob(File.join(File.dirname(__FILE__), 'xxxx/**/*.rb')).each do |file|
  BW.require file
end

Just to be clear; you don't need to glob your path first, as BW will do this for you:

BW.require File.join(File.dirname(__FILE__), 'xxxx/**/*.rb'))

You also don't need to force an absolute path:

BW.require 'lib/xxxx/**/*.rb'

works just as well, although we always encourage putting your RubyMotion code in a different location so that it never gets confused with the build code. In BubbleWrap we use motion:

BW.require 'motion/**/*.rb'

If you need help then you can always ask on #bubblewrap on freenode, or the BubbleWrap google group.