Renaming to CouchRest Model
Refactored basic directory structure. Moved to ActiveSupport for Validations and Callbacks. Cleaned up older code, and removed support for text property types.
This commit is contained in:
parent
9f1eea8d32
commit
c280b3a29b
70 changed files with 1725 additions and 3733 deletions
19
lib/couchrest/model/support/couchrest.rb
Normal file
19
lib/couchrest/model/support/couchrest.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
module CouchRest
|
||||
|
||||
class Database
|
||||
|
||||
alias :delete_old! :delete!
|
||||
def delete!
|
||||
clear_model_fresh_cache
|
||||
delete_old!
|
||||
end
|
||||
|
||||
# If the database is deleted, ensure that the design docs will be refreshed.
|
||||
def clear_model_fresh_cache
|
||||
::CouchRest::Model::Base.subclasses.each{|klass| klass.req_design_doc_refresh if klass.respond_to?(:req_design_doc_refresh)}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
32
lib/couchrest/model/support/rails.rb
Normal file
32
lib/couchrest/model/support/rails.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
# This file contains various hacks for Rails compatibility.
|
||||
class Hash
|
||||
# Hack so that CouchRest::Document, which descends from Hash,
|
||||
# doesn't appear to Rails routing as a Hash of options
|
||||
def self.===(other)
|
||||
return false if self == Hash && other.is_a?(CouchRest::Document)
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
CouchRest::Document.class_eval do
|
||||
# Need this when passing doc to a resourceful route
|
||||
alias_method :to_param, :id
|
||||
|
||||
# Hack so that CouchRest::Document, which descends from Hash,
|
||||
# doesn't appear to Rails routing as a Hash of options
|
||||
def is_a?(o)
|
||||
return false if o == Hash
|
||||
super
|
||||
end
|
||||
alias_method :kind_of?, :is_a?
|
||||
end
|
||||
|
||||
CouchRest::Model::CastedModel.class_eval do
|
||||
# The to_param method is needed for rails to generate resourceful routes.
|
||||
# In your controller, remember that it's actually the id of the document.
|
||||
def id
|
||||
return nil if base_doc.nil?
|
||||
base_doc.id
|
||||
end
|
||||
alias_method :to_param, :id
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue