searcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/searcher/class_methods.rb +3 -3
- data/lib/searcher/config.rb +3 -3
- data/lib/searcher/version.rb +1 -1
- data/lib/searcher.rb +1 -1
- data/searcher.sqlite3 +0 -0
- data/spec/fixtures/models.rb +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -22,8 +22,8 @@ To define labels for your field, use the `searcher` method inside your model lik
|
|
22
22
|
has_and_belongs_to_many :tags
|
23
23
|
|
24
24
|
searcher do
|
25
|
-
|
26
|
-
|
25
|
+
label :tag, :from => :tags, :field => "name"
|
26
|
+
label :state, :from => :state, :field => "name"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -13,9 +13,9 @@ module Searcher
|
|
13
13
|
result = query.split(" ").inject(klass) do |k, piece|
|
14
14
|
if piece.include?(":")
|
15
15
|
name, q = piece.split(":")
|
16
|
-
|
17
|
-
next unless
|
18
|
-
send("by_#{name}", q,
|
16
|
+
label = @config[:labels][name.to_sym]
|
17
|
+
next unless label
|
18
|
+
send("by_#{name}", q, label[:field])
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/lib/searcher/config.rb
CHANGED
@@ -9,9 +9,9 @@ module Searcher
|
|
9
9
|
@config
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
@config[:
|
14
|
-
@config[:
|
12
|
+
def label(field, options)
|
13
|
+
@config[:labels] ||= {}
|
14
|
+
@config[:labels][field.to_sym] = options
|
15
15
|
@config
|
16
16
|
end
|
17
17
|
end
|
data/lib/searcher/version.rb
CHANGED
data/lib/searcher.rb
CHANGED
@@ -13,7 +13,7 @@ ActiveRecord::Base.extend(Searcher::ClassMethods)
|
|
13
13
|
ActiveSupport.on_load(:after_initialize) do
|
14
14
|
Searcher.classes.each do |klass|
|
15
15
|
table = Table(klass.table_name)
|
16
|
-
klass.searcher[:
|
16
|
+
klass.searcher[:labels].each do |name, config|
|
17
17
|
association = klass.reflect_on_association(config[:from])
|
18
18
|
association_table = Table(association.klass.table_name)
|
19
19
|
if [:has_and_belongs_to_many, :belongs_to].include?(association.macro)
|
data/searcher.sqlite3
CHANGED
Binary file
|
data/spec/fixtures/models.rb
CHANGED
@@ -3,8 +3,8 @@ class Ticket < ActiveRecord::Base
|
|
3
3
|
belongs_to :state
|
4
4
|
|
5
5
|
searcher do
|
6
|
-
|
7
|
-
|
6
|
+
label :tag, :from => :tags, :field => "name"
|
7
|
+
label :state, :from => :state, :field => "name"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-05 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|