Created
October 13, 2009 20:57
-
-
Save kennethkalmer/209548 to your computer and use it in GitHub Desktop.
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
# Pseudo class | |
class SearchResult < ActiveRecord::Base | |
has_no_table | |
class << self | |
def has_many( klass ) | |
# This is almost definitely wrong, but the idea is here | |
define_method( klass.name.tableize ) do | |
klass.for_search_term( self.id ) | |
end | |
end | |
end | |
def id | |
# search terms preferably, i think... | |
end | |
end | |
# | |
# Magic mixins | |
# | |
module LinkToSearch | |
def self.included( base ) | |
base.extend( ClassMethods ) | |
end | |
module ClassMethods | |
# Setup search "association" | |
def belongs_to_search_result | |
include( InstanceMethods ) | |
extend( SingletonMethods ) | |
named_scope :for_search_term, lambda { |term| { :conditions => { :search_term => term } } } | |
SearchResult.has_many( self ) | |
end | |
end | |
module InstanceMethods | |
# This would be akin to calling an association | |
def search_result | |
# No idea what to do here really | |
end | |
end | |
module SingletonMethods | |
end | |
end | |
# Mix this into AR | |
ActiveRecord::Base.send( :include, LinkToSearch ) | |
# Link a model to search | |
class Comment < ActiveRecord::Base | |
belongs_to_search_result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment