Skip to content

Commit

Permalink
Adding placeholders to ThinkingSphinx::DataMapper, further neatening …
Browse files Browse the repository at this point in the history
…of ThinkingSphinx::ActiveRecord.
  • Loading branch information
pat committed Dec 7, 2009
1 parent adffbd2 commit f8692ab
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 55 deletions.
108 changes: 53 additions & 55 deletions lib/thinking_sphinx/active_record.rb
Expand Up @@ -3,72 +3,70 @@
require 'thinking_sphinx/active_record/attribute_updates'
require 'thinking_sphinx/active_record/has_many_association'

module ThinkingSphinx
# Core additions to ActiveRecord models - define_index for creating indexes
# for models. If you want to interrogate the index objects created for the
# model, you can use the class-level accessor :sphinx_indexes.
#
module ActiveRecord
def self.included(base)
base.class_eval do
extend ThinkingSphinx::ActiveRecord::ClassMethods
end
# Core additions to ActiveRecord models - define_index for creating indexes
# for models. If you want to interrogate the index objects created for the
# model, you can use the class-level accessor :sphinx_indexes.
#
module ThinkingSphinx::ActiveRecord
def self.included(base)
base.class_eval do
extend ThinkingSphinx::ActiveRecord::ClassMethods
end
end

module ClassMethods
def set_sphinx_primary_key(attribute)
@sphinx_primary_key_attribute = attribute
end

module ClassMethods
def set_sphinx_primary_key(attribute)
@sphinx_primary_key_attribute = attribute
end

def primary_key_for_sphinx
@sphinx_primary_key_attribute || primary_key
end

private

def add_initial_sphinx_callbacks
super

before_validation :process_indexes
before_destroy :process_indexes
end
def primary_key_for_sphinx
@sphinx_primary_key_attribute || primary_key
end

private

def add_initial_sphinx_callbacks
super

def add_standard_sphinx_callbacks
super

after_destroy :toggle_deleted

include ThinkingSphinx::ActiveRecord::AttributeUpdates
end
before_validation :process_indexes
before_destroy :process_indexes
end

def add_standard_sphinx_callbacks
super

def add_delta_sphinx_callbacks
super

before_save :toggle_delta
after_commit :index_delta
end
after_destroy :toggle_deleted

def absolute_superclass
::ActiveRecord::Base
end
include ThinkingSphinx::ActiveRecord::AttributeUpdates
end

# Returns the unique integer id for the object. This method uses the
# attribute hash to get around ActiveRecord always mapping the #id method
# to whatever the real primary key is (which may be a unique string hash).
#
# @return [Integer] Unique record id for the purposes of Sphinx.
#
def primary_key_for_sphinx
@primary_key_for_sphinx ||= read_attribute(self.class.primary_key_for_sphinx)
def add_delta_sphinx_callbacks
super

before_save :toggle_delta
after_commit :index_delta
end

private

def process_indexes
self.class.process_indexes
def absolute_superclass
::ActiveRecord::Base
end
end

# Returns the unique integer id for the object. This method uses the
# attribute hash to get around ActiveRecord always mapping the #id method
# to whatever the real primary key is (which may be a unique string hash).
#
# @return [Integer] Unique record id for the purposes of Sphinx.
#
def primary_key_for_sphinx
@primary_key_for_sphinx ||= read_attribute(self.class.primary_key_for_sphinx)
end

private

def process_indexes
self.class.process_indexes
end
end

ActiveRecord::Base.class_eval do
Expand Down
39 changes: 39 additions & 0 deletions lib/thinking_sphinx/data_mapper.rb
@@ -1,3 +1,42 @@
module ThinkingSphinx::DataMapper
def self.included(base)
base.class_eval do
extend ThinkingSphinx::DataMapper::ClassMethods
end
end

module ClassMethods
private

def add_initial_sphinx_callbacks
super

# before_validation :process_indexes
# before_destroy :process_indexes
end

def add_standard_sphinx_callbacks
super

# after_destroy :toggle_deleted

# include ThinkingSphinx::ActiveRecord::AttributeUpdates
end

def add_delta_sphinx_callbacks
super

# before_save :toggle_delta
# after_commit :index_delta
end
end

def primary_key_for_sphinx
id
end
end

DataMapper::Resource.class_eval do
include ThinkingSphinx::Base
include ThinkingSphinx::DataMapper
end

0 comments on commit f8692ab

Please sign in to comment.