Simplifying design docs
This commit is contained in:
parent
0e282f0727
commit
e6604a0990
|
@ -67,7 +67,7 @@ JAVASCRIPT
|
||||||
def has_view?(view)
|
def has_view?(view)
|
||||||
view = view.to_s
|
view = view.to_s
|
||||||
self['views'][view] &&
|
self['views'][view] &&
|
||||||
(self['views'][view]["couchrest-defaults"]||{})
|
(self['views'][view]["couchrest-defaults"] || {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_view view_name, opts, &block
|
def fetch_view view_name, opts, &block
|
||||||
|
|
|
@ -30,6 +30,7 @@ module CouchRest
|
||||||
|
|
||||||
def default_design_doc
|
def default_design_doc
|
||||||
{
|
{
|
||||||
|
"_id" => design_doc_id,
|
||||||
"language" => "javascript",
|
"language" => "javascript",
|
||||||
"views" => {
|
"views" => {
|
||||||
'all' => {
|
'all' => {
|
||||||
|
@ -60,7 +61,6 @@ module CouchRest
|
||||||
def refresh_design_doc(db = database)
|
def refresh_design_doc(db = database)
|
||||||
raise "Database missing for design document refresh" if db.nil?
|
raise "Database missing for design document refresh" if db.nil?
|
||||||
unless design_doc_fresh(db)
|
unless design_doc_fresh(db)
|
||||||
#reset_design_doc(db)
|
|
||||||
save_design_doc(db)
|
save_design_doc(db)
|
||||||
design_doc_fresh(db, true)
|
design_doc_fresh(db, true)
|
||||||
end
|
end
|
||||||
|
@ -91,32 +91,22 @@ module CouchRest
|
||||||
end
|
end
|
||||||
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
|
# Writes out a design_doc to a given database, returning the
|
||||||
# updated design doc
|
# updated design doc
|
||||||
def update_design_doc(design_doc, db, force = false)
|
def update_design_doc(design_doc, db, force = false)
|
||||||
saved = stored_design_doc(db)
|
saved = stored_design_doc(db)
|
||||||
if saved
|
if saved
|
||||||
# Perform Hash comparison on views, only part that interests us
|
changes = force
|
||||||
if force || design_doc['views'] != saved['views']
|
design_doc['views'].each do |name, view|
|
||||||
design_doc['views'].each do |name, view|
|
if saved['views'][name] != view
|
||||||
|
changes = true
|
||||||
saved['views'][name] = view
|
saved['views'][name] = view
|
||||||
end
|
end
|
||||||
db.save_doc(saved)
|
|
||||||
saved
|
|
||||||
else
|
|
||||||
design_doc
|
|
||||||
end
|
end
|
||||||
|
if changes
|
||||||
|
db.save_doc(saved)
|
||||||
|
end
|
||||||
|
design_doc
|
||||||
else
|
else
|
||||||
design_doc.database = db
|
design_doc.database = db
|
||||||
design_doc.save
|
design_doc.save
|
||||||
|
|
|
@ -87,7 +87,7 @@ module CouchRest
|
||||||
req_design_doc_refresh
|
req_design_doc_refresh
|
||||||
end
|
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)
|
def has_view?(view)
|
||||||
view = view.to_s
|
view = view.to_s
|
||||||
design_doc && design_doc['views'] && design_doc['views'][view]
|
design_doc && design_doc['views'] && design_doc['views'][view]
|
||||||
|
@ -143,7 +143,6 @@ module CouchRest
|
||||||
|
|
||||||
end # module ClassMethods
|
end # module ClassMethods
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
require File.expand_path('../../../spec_helper', __FILE__)
|
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', 'card')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'cat')
|
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', 'question')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'course')
|
require File.join(FIXTURE_PATH, 'more', 'course')
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require File.expand_path("../../../spec_helper", __FILE__)
|
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', 'card')
|
||||||
require File.join(FIXTURE_PATH, 'more', 'course')
|
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
|
class Cat < CouchRest::ExtendedDocument
|
||||||
include ::CouchRest::Validation
|
include ::CouchRest::Validation
|
||||||
|
|
||||||
|
@ -10,11 +20,3 @@ class Cat < CouchRest::ExtendedDocument
|
||||||
property :number
|
property :number
|
||||||
end
|
end
|
||||||
|
|
||||||
class CatToy < Hash
|
|
||||||
include ::CouchRest::CastedModel
|
|
||||||
include ::CouchRest::Validation
|
|
||||||
|
|
||||||
property :name
|
|
||||||
|
|
||||||
validates_presence_of :name
|
|
||||||
end
|
|
|
@ -3,4 +3,3 @@
|
||||||
progress
|
progress
|
||||||
--loadby
|
--loadby
|
||||||
mtime
|
mtime
|
||||||
--reverse
|
|
Loading…
Reference in a new issue