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.