Created
November 16, 2010 14:11
-
-
Save ernie/701856 to your computer and use it in GitHub Desktop.
A really evil trick to get at the wrapped AR model in a class method
This file contains hidden or 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
def initialize(base_or_relation, opts = {}) | |
@relation = base_or_relation.scoped | |
@base = @relation.klass | |
@search_key = opts[:search_key] ? opts[:search_key].to_s : 'search' | |
@join_dependency = build_join_dependency | |
@search_attributes = {} | |
@errors = ActiveModel::Errors.new(self) | |
singleton_class.instance_eval "def base; #{@base} end" | |
end | |
# We need the base at the singleton_class level to play nice with i18n. | |
# If anyone's got a less evil solution than this, I'm all ears. | |
def class | |
singleton_class | |
end |
I was expecting to be condemned to coder hell, where I would only be allowed to code in Visual Basic. Sounds like you're letting me off easy. That being said, I already changed it, and I'm still not happy with things. activerecord-hackery/meta_search@0997c3d
I'm beginning to think I'm in for a much larger refactor. I really don't want to pollute the AR::Base namespace the way that Searchlogic does, though.
90 days is enough to think about what you've done and how you can do it better. No one deserves a permanent condemnation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Punishable by 90 days in jail.