Module: CouchPotato
- Defined in:
- lib/couch_potato.rb,
lib/couch_potato/railtie.rb,
lib/couch_potato/version.rb,
lib/couch_potato/database.rb,
lib/couch_potato/validation.rb,
lib/couch_potato/view/lists.rb,
lib/couch_potato/persistence.rb,
lib/couch_potato/rspec/matchers.rb,
lib/couch_potato/view/view_query.rb,
lib/couch_potato/persistence/json.rb,
lib/couch_potato/view/custom_views.rb,
lib/couch_potato/view/raw_view_spec.rb,
lib/couch_potato/view/base_view_spec.rb,
lib/couch_potato/view/model_view_spec.rb,
lib/couch_potato/persistence/callbacks.rb,
lib/couch_potato/view/custom_view_spec.rb,
lib/couch_potato/persistence/properties.rb,
lib/couch_potato/persistence/attachments.rb,
lib/couch_potato/persistence/type_caster.rb,
lib/couch_potato/view/properties_view_spec.rb,
lib/couch_potato/persistence/simple_property.rb,
lib/couch_potato/persistence/dirty_attributes.rb,
lib/couch_potato/persistence/ghost_attributes.rb,
lib/couch_potato/persistence/magic_timestamps.rb,
lib/couch_potato/rspec/matchers/map_to_matcher.rb,
lib/couch_potato/rspec/matchers/list_as_matcher.rb,
lib/couch_potato/forbidden_attributes_protection.rb,
lib/couch_potato/rspec/matchers/reduce_to_matcher.rb,
lib/couch_potato/persistence/active_model_compliance.rb,
lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb
Defined Under Namespace
Modules: Attachments, ForbiddenAttributesProtection, GhostAttributes, MagicTimestamps, Persistence, RSpec, Validation, View Classes: Conflict, Database, NotFound, Railtie
Constant Summary collapse
- Config =
Struct.new(:database_host, :database_name, :split_design_documents_per_view, :default_language).new
- VERSION =
"1.1.2"
Class Method Summary collapse
-
.couchrest_database ⇒ Object
Returns the underlying CouchRest database object if you want low level access to your CouchDB.
-
.couchrest_database_for_name(database_name) ⇒ Object
Returns a CouchRest-Database for directly accessing that functionality.
-
.couchrest_database_for_name!(database_name) ⇒ Object
Creates a CouchRest-Database for directly accessing that functionality.
-
.database ⇒ Object
Returns a database instance which you can then use to create objects and query views.
-
.models ⇒ Object
returns all the classes that include the CouchPotato::Persistence module.
- .rails_init ⇒ Object
-
.use(database_name) ⇒ Object
Returns a specific database instance.
-
.with_database(database_name) {|| ... } ⇒ Object
Executes a block of code and yields a datbase with the given name.
Class Method Details
.couchrest_database ⇒ Object
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.
31 32 33 |
# File 'lib/couch_potato.rb', line 31 def self.couchrest_database @@__couchrest_database ||= CouchRest.database(full_url_to_database(CouchPotato::Config.database_name, CouchPotato::Config.database_host)) end |
.couchrest_database_for_name(database_name) ⇒ Object
Returns a CouchRest-Database for directly accessing that functionality.
56 57 58 |
# File 'lib/couch_potato.rb', line 56 def self.couchrest_database_for_name(database_name) CouchRest.database(full_url_to_database(database_name, CouchPotato::Config.database_host)) end |
.couchrest_database_for_name!(database_name) ⇒ Object
Creates a CouchRest-Database for directly accessing that functionality.
61 62 63 |
# File 'lib/couch_potato.rb', line 61 def self.couchrest_database_for_name!(database_name) CouchRest.database!(full_url_to_database(database_name)) end |
.database ⇒ Object
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.
26 27 28 |
# File 'lib/couch_potato.rb', line 26 def self.database @@__database ||= Database.new(self.couchrest_database) end |
.models ⇒ Object
returns all the classes that include the CouchPotato::Persistence module
20 21 22 23 |
# File 'lib/couch_potato.rb', line 20 def self.models @models ||= [] @models end |
.rails_init ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/couch_potato/railtie.rb', line 5 def self.rails_init path = Rails.root.join('config/couchdb.yml') if File.exist?(path) config = YAML::load(ERB.new(File.read(path)).result)[Rails.env] if config.is_a?(String) CouchPotato::Config.database_name = config else CouchPotato::Config.database_name = config['database'] CouchPotato::Config.split_design_documents_per_view = config['split_design_documents_per_view'] if config['split_design_documents_per_view'] CouchPotato::Config.default_language = config['default_language'] if config['default_language'] end else Rails.logger.warn "Rails.root/config/couchdb.yml does not exist. Not configuring a database." end end |
.use(database_name) ⇒ Object
Returns a specific database instance
36 37 38 39 40 |
# File 'lib/couch_potato.rb', line 36 def self.use(database_name) @@__databases ||= {} @@__databases["#{database_name}"] = Database.new(couchrest_database_for_name!(database_name)) unless @@__databases["#{database_name}"] @@__databases["#{database_name}"] end |
.with_database(database_name) {|| ... } ⇒ Object
Executes a block of code and yields a datbase with the given name.
example:
CouchPotato.with_database('couch_customer') do |couch|
couch.save @customer
end
49 50 51 52 53 |
# File 'lib/couch_potato.rb', line 49 def self.with_database(database_name) @@__databases ||= {} @@__databases["#{database_name}"] = Database.new(couchrest_database_for_name(database_name)) unless @@__databases["#{database_name}"] yield(@@__databases["#{database_name}"]) end |