without_ar.rb
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module ActsAsFerret
# Include this module to use acts_as_ferret with model classes
# not based on ActiveRecord.
#
# Implement the find_for_id(id) class method in your model class in
# order to make search work.
module WithoutAR
def self.included(target)
target.extend ClassMethods
target.extend ActsAsFerret::ActMethods
target.send :include, InstanceMethods
end
module ClassMethods
def logger
RAILS_DEFAULT_LOGGER
end
def table_name
self.name.underscore
end
def primary_key
'id'
end
def find(what, args = {})
case what
when :all
ids = args[:conditions][1]
ids.map { |id| find id }
else
find_for_id what
end
end
def find_for_id(id)
raise NotImplementedError.new("implement find_for_id in class #{self.name}")
end
def count
0
end
end
module InstanceMethods
def logger
self.class.logger
end
end
end
end