search_magic 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock
CHANGED
@@ -87,7 +87,7 @@ module SearchMagic
|
|
87
87
|
def update_associated_documents
|
88
88
|
self.class.inverse_searchables.each do |relation_name|
|
89
89
|
relation = send(relation_name)
|
90
|
-
|
90
|
+
Array.wrap(relation).each(&:save!)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -20,7 +20,7 @@ module SearchMagic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def arrangeable_value_for(obj)
|
23
|
-
get_value(obj)
|
23
|
+
post_process(get_value(obj))
|
24
24
|
end
|
25
25
|
|
26
26
|
def searchable_value_for(obj)
|
@@ -32,5 +32,20 @@ module SearchMagic
|
|
32
32
|
def get_value(obj)
|
33
33
|
self.through.map(&:field_name).inject(obj) {|memo, method| memo.is_a?(Array) ? memo.map{|o| o.send(method)} : memo.send(method)}
|
34
34
|
end
|
35
|
+
|
36
|
+
def post_process(value)
|
37
|
+
value.is_a?(Array) ? value.map {|obj| convert_date_to_time(obj)} : convert_date_to_time(value)
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert_date_to_time(value)
|
41
|
+
case value.class.name
|
42
|
+
when "Date"
|
43
|
+
value.to_time
|
44
|
+
when "DateTime"
|
45
|
+
value.utc.to_time.localtime
|
46
|
+
else
|
47
|
+
value
|
48
|
+
end
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/search_magic/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CustomMethodSearchable
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include SearchMagic::FullTextSearch
|
5
|
+
|
6
|
+
search_on :random_value
|
7
|
+
search_on :date_value
|
8
|
+
|
9
|
+
def random_value
|
10
|
+
@random_value ||= rand(100)
|
11
|
+
end
|
12
|
+
|
13
|
+
def date_value
|
14
|
+
(created_at || Time.now).to_date + 15
|
15
|
+
end
|
16
|
+
end
|
@@ -29,6 +29,20 @@ describe SearchMagic::FullTextSearch do
|
|
29
29
|
its("arrangeable_values.keys") { should_not include(:uuid) }
|
30
30
|
end
|
31
31
|
|
32
|
+
context "when saving a model with custom method arrangeables which yeild dates" do
|
33
|
+
subject { CustomMethodSearchable.new }
|
34
|
+
its("class.searchables.keys") { should_not be_empty }
|
35
|
+
its("class.searchables.keys") { should include(:random_value, :date_value)}
|
36
|
+
it { expect { subject.save }.not_to raise_error }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when saving a model with custom method arrangeables" do
|
40
|
+
subject { CustomMethodSearchable.new }
|
41
|
+
before(:each) { subject.save }
|
42
|
+
its(:arrangeable_values) { should_not be_empty }
|
43
|
+
its("arrangeable_values.keys") { should include(:random_value, :date_value)}
|
44
|
+
end
|
45
|
+
|
32
46
|
context "when :arrange is performed on a model with :searchables" do
|
33
47
|
before(:each) do
|
34
48
|
Asset.create(:title => "Foo Bar: The Bazzening", :description => "Sequel to last years hit summer blockbuster.", :tags => ["movies", "suspense", "foo.bar", "the-bazzening"])
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: search_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joshua Bowers
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-11 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- spec/models/absolutely_not_searchable.rb
|
83
83
|
- spec/models/address.rb
|
84
84
|
- spec/models/asset.rb
|
85
|
+
- spec/models/custom_method_searchable.rb
|
85
86
|
- spec/models/developer.rb
|
86
87
|
- spec/models/game.rb
|
87
88
|
- spec/models/graph_1_model_a.rb
|
@@ -132,6 +133,7 @@ test_files:
|
|
132
133
|
- spec/models/absolutely_not_searchable.rb
|
133
134
|
- spec/models/address.rb
|
134
135
|
- spec/models/asset.rb
|
136
|
+
- spec/models/custom_method_searchable.rb
|
135
137
|
- spec/models/developer.rb
|
136
138
|
- spec/models/game.rb
|
137
139
|
- spec/models/graph_1_model_a.rb
|