Using Couchbase Lite from RubyMotion

CouchbaseLite has been released for sometime now, so I thought it is time to
give an update for using CouchbaseLite from RubyMotion.

When I ported ToDoLite-iOS to
RubyMotion originally there where some bumps in the road, but it worked over
all. There were for example some problems with RubyMotion not handling lambdas
the way CouchbaseLite needs them, but this has been resolved since then. If you
don’t know what I mean by that, you can be happy and forget all about it, or
read up on
it
.

So what do I need now to get going with CouchbaseLite and iOS?

By now it is possible to go 100% ruby for a RubyMotion project using
CouchbaseLite, which is great. CouchbaseLite has been publicly released, is out
of beta and has already received much love in terms of patches to make it work
even more reliably cross all platforms. In case of RubyMotion this made things
much easier, and the process is by now:

  • Add couchbase-lite via cocoapods
  • Tell rubymotion where to find the header files
  • Use it!

Installing CouchbaseLite via Cocoapods

Cocoapods is an awesome package manager for iOS and
MacOS projects, and it integrates really well with RubyMotion. All there is todo
is add cocoapods and motion-cocoapods to your gemfile

http://gist-it.appspot.com/github/couchbaselabs/TodoLite-Motion/blob/d07672075a934d74ed1aac9955369076e7ac3ab2/Gemfile

Now you can install any cocoapods by adding them to the Rakefile and running
“bundle exec rake pod:install”

http://gist-it.appspot.com/github/couchbaselabs/TodoLite-Motion/blob/d07672075a934d74ed1aac9955369076e7ac3ab2/Rakefile?slice=7:33

Important side not, make sure to include

http://gist-it.appspot.com/github/couchbaselabs/TodoLite-Motion/blob/d07672075a934d74ed1aac9955369076e7ac3ab2/Rakefile?slice=22:26

as the headers are not going to be found otherwise.

Using Couchbase Lite from RubyMotion

You can now use CouchbaseLite like you would any other Obj-C library from
rubymotion, for example to define a view which grabs all the “lists” in the
database you can write this

http://gist-it.appspot.com/github/couchbaselabs/TodoLite-Motion/blob/d07672075a934d74ed1aac9955369076e7ac3ab2/app/models/list.rb?slice=7:17

For more details checkout the RubyMotion Sample project on
Github
.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s