DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Couchbase Lite from RubyMotion
Content provided by Couchbase logo

Using Couchbase Lite from RubyMotion

Don Pinto user avatar by
Don Pinto
·
Oct. 30, 14 · Interview
Like (1)
Save
Tweet
Share
3.98K Views

Originally written by Philipp Fehre

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

When I ported ToDoLite-iOS to RubyMotion originally there where some bumps in the road, but it worked over all. For example, there were 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 Couchbase Lite and iOS?

By now it is possible to go 100% Ruby for a RubyMotion project using Couchbase Lite, which is great. Couchbase Lite 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 the 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 Couchbase Lite 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:

source 'https://rubygems.org'

gem 'rake'

# Build dependencies:
gem 'cocoapods', '~> 0.33.1'
gem 'motion-cocoapods', '~> 1.4.0'

# Add your dependencies:
gem 'bubble-wrap', '~> 1.5.0'

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

Motion::Project::App.setup do |app|
  # Use `rake config' to see complete project settings.
  app.name = 'ToDoLite-Motion'
  app.frameworks += ['Accounts', 'Social']
  app.identifier = 'com.couchbase.ToDoLite-Motion'

  # Add config directory files
  app.files << Dir.glob('./config/*.rb')

  # Make sure the CouchbaseLite Headers are found
  # this makes CocoaPods kind of redundant but currently is the only way this works
  #
  # http://equip9.org/2014/03/06/adding-couchbase-in-a-rubymotion-app.html
  # https://groups.google.com/forum/#!topic/rubymotion/wVqdLWQ5uao
  #
  app.vendor_project('vendor/Pods/couchbase-lite-ios/CouchbaseLite.framework',
                     :static,
                     products: ['CouchbaseLite'],
                     headers_dir: 'Headers')

  app.codesign_certificate = 'iPhone Developer: Philipp Fehre (6W7Y595HZQ)'

  app.pods do
    pod 'couchbase-lite-ios', '~> 1.0'
  end
end

Important side note, make sure to include:

app.vendor_project('vendor/Pods/couchbase-lite-ios/CouchbaseLite.framework',
                     :static,
                     products: ['CouchbaseLite'],
                     headers_dir: 'Headers')

as the headers are not going to be found otherwise.

Using Couchbase Lite from RubyMotion

You can now use Couchbase Lite like you would any other Obj-C library from RubyMotion. For example, to define a view that grabs all the "lists" in the database you can write this:

def self.queryListsInDatabase database
    view = database.viewNamed("lists")
    if !view.mapBlock
      map = lambda { |doc, emit|
        emit.call(doc["title"], nil) if doc["type"] == "list"
      }
      view.setMapBlock map, reduceBlock: nil, version: "2"
    end
    view.createQuery
  end

For more details check out the RubyMotion Sample project on Github.



Comments

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: