check if Rails exists for the rails support
This commit is contained in:
parent
7246801f57
commit
36f69ec332
|
@ -1,19 +1,17 @@
|
||||||
# This file contains various hacks for Rails compatibility.
|
# This file contains various hacks for Rails compatibility.
|
||||||
# To use, just require in environment.rb, like so:
|
|
||||||
#
|
|
||||||
# require 'couchrest/support/rails'
|
|
||||||
|
|
||||||
class Hash
|
if defined?(Rails)
|
||||||
|
|
||||||
|
class Hash
|
||||||
# Hack so that CouchRest::Document, which descends from Hash,
|
# Hack so that CouchRest::Document, which descends from Hash,
|
||||||
# doesn't appear to Rails routing as a Hash of options
|
# doesn't appear to Rails routing as a Hash of options
|
||||||
def self.===(other)
|
def self.===(other)
|
||||||
return false if self == Hash && other.is_a?(CouchRest::Document)
|
return false if self == Hash && other.is_a?(CouchRest::Document)
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
CouchRest::Document.class_eval do
|
||||||
CouchRest::Document.class_eval do
|
|
||||||
# Need this when passing doc to a resourceful route
|
# Need this when passing doc to a resourceful route
|
||||||
alias_method :to_param, :id
|
alias_method :to_param, :id
|
||||||
|
|
||||||
|
@ -29,9 +27,9 @@ CouchRest::Document.class_eval do
|
||||||
def logger
|
def logger
|
||||||
ActiveRecord::Base.logger
|
ActiveRecord::Base.logger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CouchRest::CastedModel.class_eval do
|
CouchRest::CastedModel.class_eval do
|
||||||
# The to_param method is needed for rails to generate resourceful routes.
|
# 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.
|
# In your controller, remember that it's actually the id of the document.
|
||||||
def id
|
def id
|
||||||
|
@ -39,14 +37,16 @@ CouchRest::CastedModel.class_eval do
|
||||||
base_doc.id
|
base_doc.id
|
||||||
end
|
end
|
||||||
alias_method :to_param, :id
|
alias_method :to_param, :id
|
||||||
end
|
end
|
||||||
|
|
||||||
require Pathname.new(File.dirname(__FILE__)).join('..', 'validation', 'validation_errors')
|
require Pathname.new(File.dirname(__FILE__)).join('..', 'validation', 'validation_errors')
|
||||||
|
|
||||||
CouchRest::Validation::ValidationErrors.class_eval do
|
CouchRest::Validation::ValidationErrors.class_eval do
|
||||||
# Returns the total number of errors added. Two errors added to the same attribute will be counted as such.
|
# Returns the total number of errors added. Two errors added to the same attribute will be counted as such.
|
||||||
# This method is called by error_messages_for
|
# This method is called by error_messages_for
|
||||||
def count
|
def count
|
||||||
errors.values.inject(0) { |error_count, errors_for_attribute| error_count + errors_for_attribute.size }
|
errors.values.inject(0) { |error_count, errors_for_attribute| error_count + errors_for_attribute.size }
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue