Create gems for RubyMotion

While RubyMotion featured using rubygems to extend projects, the actual
steps to do so is not documented until motion-redgreen gems demonstrate it.

Define A Gem

Making gem for Motion is not unlike that for standard gems, with
some exceptions.

To add a gem to your RubyMotion project, instead of using rubygems to require source files in runtime, you
require it in project Rakefile.

Inside the source file being required, instead of require other files normally you would in rubygems, use
Motion::Project::App.setup to add sources to your motion project:

unless defined?(Motion::Project::Config)
  raise "This file must be required within a RubyMotion project Rakefile."
end

Motion::Project::App.setup do |app|
  Dir.glob(File.join(File.dirname(__FILE__), 'nano_store/*.rb')).each do |file|
    app.files.unshift(file)
  end
end

Adding Source Files

You can add files to the project with app.files:

Motion::Project::App.setup do |app|
  Dir.glob(File.join(File.dirname(__FILE__), 'bubble-wrap/*.rb')).each do |file|
    app.files.unshift(file)
  end
end

Adding Libraries, Frameworks or External Projects

Add libraries, framework or external projects as you normally would:

Motion::Project::App.setup do |app|
  Dir.glob(File.join(File.dirname(__FILE__), 'motion-hpple/*.rb')).each do |file|
    app.files.unshift(file)
  end
  app.libs << '/usr/lib/libxml2.2.dylib'

  hpple_vendor = File.expand_path(File.join(File.dirname(__FILE__), '../vendor/hpple'))
  app.vendor_project(hpple_vendor, :static)
end

Adding Cocoapods

Add cocoapods dependency with following code:

Motion::Project::App.setup do |app|
  Dir.glob(File.join(File.dirname(__FILE__), 'nano_store/*.rb')).each do |file|
    app.files.unshift(file)
  end

  app.pods ||= Motion::Project::CocoaPods.new(app)
  app.pods.dependency 'NanoStore', '~> 2.0.1'
end

If the project already using cocoapods, above code will just work. If you have not include
any other pods in the project, add following lines to the project Rakefile:

Motion::Project::App.setup do |app|
  app.name = 'myapp'

  # Only needed if you have not already specifying a pods dependency
  app.pods do
    dependency 'NanoStore', '~> 2.0.1'
  end
end

Conclusion

Now you are ready to roll. Have a look of following RubyMotion gems if you need more help: