Simplifying design docs
This commit is contained in:
parent
0e282f0727
commit
e6604a0990
|
@ -67,7 +67,7 @@ JAVASCRIPT
|
|||
def has_view?(view)
|
||||
view = view.to_s
|
||||
self['views'][view] &&
|
||||
(self['views'][view]["couchrest-defaults"]||{})
|
||||
(self['views'][view]["couchrest-defaults"] || {})
|
||||
end
|
||||
|
||||
def fetch_view view_name, opts, &block
|
||||
|
@ -76,4 +76,4 @@ JAVASCRIPT
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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']
|
||||
design_doc['views'].each do |name, view|
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
18
spec/fixtures/more/cat.rb
vendored
18
spec/fixtures/more/cat.rb
vendored
|
@ -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
|
|
@ -3,4 +3,3 @@
|
|||
progress
|
||||
--loadby
|
||||
mtime
|
||||
--reverse
|
Loading…
Reference in a new issue