Simplifying design docs

This commit is contained in:
Sam Lown 2010-04-16 02:51:59 +02:00
parent 0e282f0727
commit e6604a0990
7 changed files with 24 additions and 33 deletions

View file

@ -30,6 +30,7 @@ module CouchRest
def default_design_doc
{
"_id" => design_doc_id,
"language" => "javascript",
"views" => {
'all' => {
@ -60,7 +61,6 @@ module CouchRest
def refresh_design_doc(db = database)
raise "Database missing for design document refresh" if db.nil?
unless design_doc_fresh(db)
#reset_design_doc(db)
save_design_doc(db)
design_doc_fresh(db, true)
end
@ -91,32 +91,22 @@ module CouchRest
end
end
# Depricated (not very useful)
def reset_design_doc(db = database)
current = stored_design_doc(db)
design_doc['_id'] = design_doc_id
if current.nil?
design_doc.delete('_rev')
else
design_doc['_rev'] = current['_rev']
end
end
# Writes out a design_doc to a given database, returning the
# updated design doc
def update_design_doc(design_doc, db, force = false)
saved = stored_design_doc(db)
if saved
# Perform Hash comparison on views, only part that interests us
if force || design_doc['views'] != saved['views']
changes = force
design_doc['views'].each do |name, view|
if saved['views'][name] != view
changes = true
saved['views'][name] = view
end
db.save_doc(saved)
saved
else
design_doc
end
if changes
db.save_doc(saved)
end
design_doc
else
design_doc.database = db
design_doc.save

View file

@ -87,7 +87,7 @@ module CouchRest
req_design_doc_refresh
end
# returns stored defaults if the there is a view named this in the design doc
# returns stored defaults if there is a view named this in the design doc
def has_view?(view)
view = view.to_s
design_doc && design_doc['views'] && design_doc['views'][view]
@ -143,7 +143,6 @@ module CouchRest
end # module ClassMethods
end
end
end

View file

@ -1,9 +1,9 @@
# encoding: utf-8
require File.expand_path('../../../spec_helper', __FILE__)
require File.join(FIXTURE_PATH, 'more', 'person')
require File.join(FIXTURE_PATH, 'more', 'card')
require File.join(FIXTURE_PATH, 'more', 'cat')
require File.join(FIXTURE_PATH, 'more', 'person')
require File.join(FIXTURE_PATH, 'more', 'question')
require File.join(FIXTURE_PATH, 'more', 'course')

View file

@ -1,4 +1,5 @@
require File.expand_path("../../../spec_helper", __FILE__)
require File.join(FIXTURE_PATH, 'more', 'person')
require File.join(FIXTURE_PATH, 'more', 'card')
require File.join(FIXTURE_PATH, 'more', 'course')

View file

@ -1,3 +1,13 @@
class CatToy < Hash
include ::CouchRest::CastedModel
include ::CouchRest::Validation
property :name
validates_presence_of :name
end
class Cat < CouchRest::ExtendedDocument
include ::CouchRest::Validation
@ -10,11 +20,3 @@ class Cat < CouchRest::ExtendedDocument
property :number
end
class CatToy < Hash
include ::CouchRest::CastedModel
include ::CouchRest::Validation
property :name
validates_presence_of :name
end

View file

@ -3,4 +3,3 @@
progress
--loadby
mtime
--reverse