-
-
Save gbuesing/82606 to your computer and use it in GitHub Desktop.
Hash hacks so that CouchRest::Document plays nice with Rails routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hacks so that CouchRest::Document, which descends from Hash, | |
# doesn't appear to Rails routing as a Hash of options | |
class Hash | |
def self.===(other) | |
return false if other.is_a?(CouchRest::Document) | |
super | |
end | |
end | |
module CouchRest | |
class Document < Hash | |
def is_a?(o) | |
return false if o == Hash | |
super | |
end | |
alias_method :kind_of?, :is_a? | |
end | |
end | |
class Model < CouchRest::Document; end | |
require 'test/unit' | |
class TestCouchRestHashHacks < Test::Unit::TestCase | |
def test_case_equality | |
assert_equal true, Hash === Hash.new | |
assert_equal false, Hash === Array.new | |
assert_equal false, Hash === CouchRest::Document.new | |
assert_equal false, Hash === Model.new | |
end | |
def test_is_a | |
assert_equal true, CouchRest::Document.new.is_a?(CouchRest::Document) | |
assert_equal true, Model.new.is_a?(CouchRest::Document) | |
assert_equal false, CouchRest::Document.new.is_a?(Hash) | |
assert_equal false, Model.new.is_a?(Hash) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment