Skip to content

Instantly share code, notes, and snippets.

@shanna
Created February 10, 2010 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanna/299862 to your computer and use it in GitHub Desktop.
Save shanna/299862 to your computer and use it in GitHub Desktop.
#--
# TODO: Ask about this monkey patch or alternatively I was thinking repository.create_query(*args) which would in turn
# call the same method on the adapter. The command stuff in data objects works the same way so I don't see a good
# argument against it other than the extra dispatch would be slightly slower.
module DataMapper
class Query
extend Chainable
chainable do
def self.new(*args, &block)
super
end
end
end # Query
end # DataMapper
# Hijack the DataMapper::Query constructor allowing us to return a subclassed sphinx query object.
module DataMapper
module Sphinx
module QueryFactory
def new(repository, *args)
if repository.adapter.is_a?(Sphinx::Adapter) && self == DataMapper::Query
Sphinx::Query.new(repository, *args)
else
super
end
end
end # QueryFactory
end # Sphinx
class Query
extend Sphinx::QueryFactory
end
end # DataMapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment