Module: SimplyCouch

Defined in:
lib/simply_couch/model/belongs_to.rb,
lib/simply_couch.rb,
lib/simply_couch/model.rb,
lib/simply_couch/storage.rb,
lib/simply_couch/model/find_by.rb,
lib/simply_couch/model/finders.rb,
lib/simply_couch/model/has_one.rb,
lib/simply_couch/has_attachment.rb,
lib/simply_couch/model/ancestry.rb,
lib/simply_couch/model/database.rb,
lib/simply_couch/model/has_many.rb,
lib/simply_couch/database_config.rb,
lib/simply_couch/instance_methods.rb,
lib/simply_couch/model/pagination.rb,
lib/simply_couch/model/properties.rb,
lib/simply_couch/model/view/lists.rb,
lib/simply_couch/model/attachments.rb,
lib/simply_couch/model/embedded_in.rb,
lib/simply_couch/model/persistence.rb,
lib/simply_couch/model/validations.rb,
lib/simply_couch/class_methods_base.rb,
lib/simply_couch/model/view/view_query.rb,
lib/simply_couch/model/has_many_embedded.rb,
lib/simply_couch/model/view/custom_views.rb,
lib/simply_couch/model/pagination_options.rb,
lib/simply_couch/model/view/raw_view_spec.rb,
lib/simply_couch/model/view/base_view_spec.rb,
lib/simply_couch/model/association_property.rb,
lib/simply_couch/model/view/model_view_spec.rb,
lib/simply_couch/model/view/custom_view_spec.rb,
lib/simply_couch/model/has_and_belongs_to_many.rb,
lib/simply_couch/model/view/properties_view_spec.rb,
lib/simply_couch/model/views/deleted_model_view_spec.rb,
lib/simply_couch/model/views/array_property_view_spec.rb

Overview

require ‘active_support/core_ext/hash/except’

Defined Under Namespace

Modules: ClassMethods, HasAttachment, InstanceMethods, Model, Storage Classes: Conflict, Error, ModelNotInstantiatedError, NotImplementedError, RecordNotFound

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.current_databaseObject

Get/set the request-scoped database (delegates to app’s Current class).



52
53
54
# File 'lib/simply_couch/database_config.rb', line 52

def self.current_database
  defined?(::Current) && ::Current.respond_to?(:couch_database) ? ::Current.couch_database : nil
end

.current_database=(db) ⇒ Object



56
57
58
# File 'lib/simply_couch/database_config.rb', line 56

def self.current_database=(db)
  ::Current.couch_database = db if defined?(::Current) && ::Current.respond_to?(:couch_database=)
end

.databaseObject

Returns the effective default database (request-scoped or global).



38
39
40
# File 'lib/simply_couch/database_config.rb', line 38

def self.database
  current_database || database_for(database_url) || fallback_database
end

.database_for(url) ⇒ Object

Returns a DatabaseInstance for the given URL, caching by URL.



32
33
34
35
# File 'lib/simply_couch/database_config.rb', line 32

def self.database_for(url)
  return nil unless url
  databases[url] ||= Model::DatabaseInstance.new(url)
end

.databasesObject



62
63
64
# File 'lib/simply_couch/database_config.rb', line 62

def self.databases
  @_databases ||= {}
end

.fallback_databaseObject



66
67
68
# File 'lib/simply_couch/database_config.rb', line 66

def self.fallback_database
  database_for(ENV['COUCHDB_URL'] || 'http://127.0.0.1:5984/mozo_development')
end

.with_database(database) ⇒ Object

Temporarily switch the current database for a block.



43
44
45
46
47
48
49
# File 'lib/simply_couch/database_config.rb', line 43

def self.with_database(database)
  previous = current_database
  self.current_database = database
  yield
ensure
  self.current_database = previous
end