Skip to content

Commit

Permalink
Adding Rails-related monkeypatches file, which isn't required by defa…
Browse files Browse the repository at this point in the history
…ult. Contains fixes for Rails routing and Rails form error compatibility.
  • Loading branch information
Geoff Buesing authored and mattetti committed Apr 1, 2009
1 parent 09dcc9e commit 5f5aa06
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/couchrest/support/rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file contains various hacks for Rails compatibility.
# To use, just require in environment.rb, like so:
#
# require 'couchrest/support/rails'

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 other.is_a?(CouchRest::Document)
super
end
end


CouchRest::Document.class_eval do
# 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


require Pathname.new(File.dirname(__FILE__)).join('..', 'validation', 'validation_errors')

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.
# This method is called by error_messages_for
def count
errors.values.inject(0) { |error_count, errors_for_attribute| error_count + errors_for_attribute.size }
end
end

0 comments on commit 5f5aa06

Please sign in to comment.