Sha256: 549f0b1897a482d4e31ebc68620a5b8f63b16e0052fdc65140a5bc67e748d3ce

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

require 'couchrest'
require 'json'
require 'json/add/core'
require 'json/add/rails'

require 'ostruct'

JSON.create_id = 'ruby_class'

module CouchPotato
  Config = Struct.new(:database_name, :validation_framework, :split_design_documents_per_view).new
  Config.validation_framework = :active_model
  Config.split_design_documents_per_view = false
  
  class NotFound < StandardError; end

  # Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works.
  def self.database
    @@__database ||= Database.new(self.couchrest_database)
  end

  # Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works.
  def self.couchrest_database
    @@__couchrest_database ||= CouchRest.database(full_url_to_database)
  end

  private

  def self.full_url_to_database
    raise('No Database configured. Set CouchPotato::Config.database_name') unless CouchPotato::Config.database_name
    if CouchPotato::Config.database_name.match(%r{https?://})
      CouchPotato::Config.database_name
    else
      "http://127.0.0.1:5984/#{CouchPotato::Config.database_name}"
    end
  end
end

$LOAD_PATH << File.dirname(__FILE__)

require 'core_ext/object'
require 'core_ext/time'
require 'core_ext/date'
require 'core_ext/string'
require 'core_ext/symbol'
require 'couch_potato/validation'
require 'couch_potato/persistence'
require 'couch_potato/railtie' if defined?(Rails)

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
couch_potato-rails2-0.5.10 lib/couch_potato.rb
couch_potato-rails2-0.5.9 lib/couch_potato.rb
couch_potato-rails2-0.5.8 lib/couch_potato.rb
couch_potato-rails2-0.5.7 lib/couch_potato.rb
couch_potato-rails2-0.5.6 lib/couch_potato.rb
couch_potato-0.5.6 lib/couch_potato.rb
couch_potato-0.5.5 lib/couch_potato.rb