lib/teacup.rb in teacup-0.0.1.pre vs lib/teacup.rb in teacup-0.3.1
- old
+ new
@@ -1,41 +1,24 @@
unless defined?(Motion::Project::Config)
- raise "This file must be required within a RubyMotion project Rakefile."
+ raise "The teacup gem must be required within a RubyMotion project Rakefile."
end
-# In order that we can prepend our files to the load path after the user has
-# configured their app.files, we need to run code *after* the user has set up
-# their app.
-#
-# Unfortunately, the canonical place to require rubygems is at the top of the
-# file (while we could just add to the instructions "please `require 'teacup'`
-# at the bottom, that would be odd, and no-one would read the instructions).
-#
-# To this end, we tweak the App setup function so that whenever setup is called,
-# we configure teacup after that.
-#
-# This is not great though, as other gems may (following the instructions at
-# http://reality.hk/posts/2012/05/22/create-gems-for-rubymotion/) also call
-# setup...
-#
-# For sanity reasons, we therefore delete teacup requires from the load order
-# and re-add them to the front every single time {setup} is called.
-#
-# TODO: We should send a patch to rubymotion that adds first-class support for
-# app.gems. These could then be required *after* the user has finished running
-# the setup block, so that they can just run setup properly.
-#
-class << Motion::Project::App
- def setup_with_teacup
- setup_without_teacup do |app|
- yield app
-
- dirs = %w(teacup teacup/core_extensions)
- files = dirs.map{ |dir| Dir.glob("#{File.dirname(__FILE__)}/#{dir}/*.rb") }.flatten
- app.files = files + (app.files - files)
+Motion::Project::App.setup do |app|
+ # scans app.files until it finds app/ (the default)
+ # if found, it inserts just before those files, otherwise it will insert to
+ # the end of the list
+ insert_point = 0
+ app.files.each_index do |index|
+ file = app.files[index]
+ if file =~ /^(?:\.\/)?app\//
+ # found app/, so stop looking
+ break
end
+ insert_point = index + 1
end
- alias setup_without_teacup setup
- alias setup setup_with_teacup
+ app.files.insert(insert_point, File.join(File.dirname(__FILE__), 'dummy.rb'))
+ Dir.glob(File.join(File.dirname(__FILE__), 'teacup/**/*.rb')).reverse.each do |file|
+ app.files.insert(insert_point, file)
+ end
end