Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library Ruby 1.0
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
2.3 Not your mother's ActiveRecord
Chapter Sections
Chapters

2.3.1. Connecting to Couchbase

Listing 5: app/models/couch.rb

module Couch

      class << self

        def domain
          return "http://#{ENV['COUCHBASE_DOMAIN']}" if ENV['COUCHBASE_DOMAIN']
          case Rails.env.to_s
            when "production"  then "http://127.0.0.1"
            when "test"        then "http://127.0.0.1"
            when "development" then "http://127.0.0.1"
          end
        end

        def client
          @client ||= Couchbase.new "#{domain}:8091/pools/default"
        end

      end

    end

Because we have the concept of an environment in Rails, we wrote this small module to enable us to configure where our couchbase instance is located. Then throughout our code we can reference Couch.client which will return our Couchbase Client object.