dnif 0.0.1.alpha.3 → 0.0.1.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
data/dnif.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dnif}
8
- s.version = "0.0.1.alpha.3"
8
+ s.version = "0.0.1.alpha.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rafael Souza"]
12
- s.date = %q{2010-07-01}
12
+ s.date = %q{2010-07-02}
13
13
  s.description = %q{dnif is a gem to index data using ActiveRecord finders, letting you index your custom methods and not only your table fields}
14
14
  s.email = %q{me@rafaelss.com}
15
15
  s.extra_rdoc_files = [
@@ -26,5 +26,37 @@ module Dnif
26
26
  yield name, class_name
27
27
  end
28
28
  end
29
+
30
+ # Code extracted from Ultrasphinx
31
+ # Configuration file parser.
32
+ def self.options_for(heading, path)
33
+ # Evaluate ERB
34
+ template = ERB.new(File.open(path) {|f| f.read})
35
+ contents = template.result(binding)
36
+
37
+ # Find the correct heading.
38
+ section = contents[/^#{heading.gsub('/', '__')}\s*?\{(.*?)\}/m, 1]
39
+
40
+ if section
41
+ # Strip comments and leading/trailing whitespace
42
+ section.gsub!(/^\s*(.*?)\s*(?:#.*)?$/, '\1')
43
+
44
+ # Convert to a hash
45
+ returning({}) do |options|
46
+ lines = section.split(/\n+/)
47
+ while line = lines.shift
48
+ if line =~ /(.*?)\s*=\s*(.*)/
49
+ key, value = $1, [$2]
50
+ value << (line = lines.shift) while line =~ /\\$/
51
+ options[key] = value.join("\n ")
52
+ end
53
+ end
54
+ end
55
+ else
56
+ # XXX Is it safe to raise here?
57
+ puts "warning; heading #{heading} not found in #{path}; it may be corrupted. "
58
+ {}
59
+ end
60
+ end
29
61
  end
30
62
  end
data/lib/dnif/search.rb CHANGED
@@ -3,7 +3,9 @@ module Dnif
3
3
  def self.search(query, options = {})
4
4
  options.reverse_merge!(:index => '*')
5
5
 
6
- client = Riddle::Client.new("127.0.0.1", 3313)
6
+ Dnif.root_path ||= File.expand_path(File.dirname("."))
7
+ searchd = Dnif::Configuration.options_for("searchd", File.join(Dnif.root_path, "config/sphinx", Dnif.environment + ".erb"))
8
+ client = Riddle::Client.new(*searchd["listen"].split(":"))
7
9
 
8
10
  if not options[:class].nil?
9
11
  filter_value = Dnif::MultiAttribute.encode(options[:class]).split(",").map(&:to_i)
@@ -29,4 +29,9 @@ class TestConfiguration < Test::Unit::TestCase
29
29
  assert_equal ["users_main", "people_main", "orders_main", "notes_main"], names
30
30
  assert_equal ["User", "Person", "Order", "Note"], classes
31
31
  end
32
+
33
+ test ".options_for" do
34
+ client = Dnif::Configuration.options_for("searchd", File.join(Dnif.root_path, "templates", "config.erb"))
35
+ assert client.is_a?(Hash)
36
+ end
32
37
  end
@@ -21,7 +21,8 @@ class TestSearch < Test::Unit::TestCase
21
21
  }]
22
22
  }
23
23
 
24
- Riddle::Client.any_instance.expects(:query).times(2).with("post", "*").returns(results_for_post, results_for_comment)
24
+ Dnif::Configuration.expects(:options_for).twice.returns({ "listen" => "127.0.0.1:3333" })
25
+ Riddle::Client.any_instance.expects(:query).twice.with("post", "*").returns(results_for_post, results_for_comment)
25
26
 
26
27
  Post.expects(:find_all_by_id).once.with([1])
27
28
  Comment.expects(:find_all_by_id).once.with([2])
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 1
9
9
  - alpha
10
- - 3
11
- version: 0.0.1.alpha.3
10
+ - 4
11
+ version: 0.0.1.alpha.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Rafael Souza
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-01 00:00:00 -03:00
19
+ date: 2010-07-02 00:00:00 -03:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency