xapor 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -12,13 +12,18 @@ module Xapor::XapianFuIntegration
12
12
 
13
13
  module ClassMethods
14
14
  def xapor
15
+ class << self
16
+ attr_accessor :xapor_config
17
+ attr_accessor :xapor_db
18
+ end
19
+
15
20
  include XapianFu
16
21
 
17
- def search(query)
22
+ def self.search(query)
18
23
  xapor_db.search(query)
19
24
  end
20
25
 
21
- def reset_index
26
+ def self.reset_index
22
27
  if @db
23
28
  @db.flush
24
29
  @db.ro.close
@@ -30,28 +35,26 @@ module Xapor::XapianFuIntegration
30
35
  end
31
36
  end
32
37
 
33
- def xapor_config
34
- self.class.instance_variable_get(:@config)
35
- end
36
-
37
- def xapor_db
38
- @db ||= XapianDb.new(xapor_config.xapian_fu_db.merge(:create => true))
39
- end
40
-
41
- @config = Xapor::Config.new
38
+ self.xapor_config = Xapor::Config.new
42
39
  if block_given?
43
- yield @config
40
+ yield self.xapor_config
44
41
  end
42
+ self.xapor_db = ::XapianFu::XapianDb.new(self.xapor_config.xapian_fu_db.merge(:create => true))
45
43
 
46
- @config.search_fields.each do |field|
47
- class_eval("def self.search_by_#{field}(query)\nself.search(query)\nend")
44
+ eigenclass = class << self
45
+ self
48
46
  end
47
+ self.xapor_config.search_fields.each do |field|
48
+ eigenclass.send(:define_method, :"search_by_#{field}") do |query|
49
+ self.search(query)
50
+ end
51
+ end
49
52
 
50
53
  if defined? ActiveRecord && ancestors.includes(ActiveRecord::Base)
51
54
  after_save :add_to_index
52
55
  after_destroy :remove_from_index
53
56
  #in-memory index, needs to be indexed on startup
54
- all.each {|o| o.add_to_index} unless @config.directory_config
57
+ all.each {|o| o.add_to_index} unless self.xapor_config.directory_config
55
58
  end
56
59
  end
57
60
  end
data/xapor.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{xapor}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Workman"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Workman