soulmate_rails 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/Gemfile +4 -0
- data/Rakefile +8 -1
- data/lib/soulmate_rails/model_additions.rb +11 -12
- data/lib/soulmate_rails/version.rb +2 -2
- data/spec/soulmate_rails/model_additions_spec.rb +0 -5
- data/spec/spec_helper.rb +7 -2
- metadata +5 -5
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.3@soulmate_rails --create
|
1
|
+
rvm 1.9.3-p385@soulmate_rails --create
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -20,5 +20,12 @@ end
|
|
20
20
|
|
21
21
|
desc 'Open an irb session preloaded with this library'
|
22
22
|
task :console do
|
23
|
-
sh 'irb -rubygems -I lib -r soulmate_rails.rb'
|
23
|
+
sh 'irb -rubygems -I lib:spec -r soulmate_rails.rb -r spec_helper.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Release the gem'
|
27
|
+
task :release => :build do
|
28
|
+
sh "git tag -a 'v#{SoulmateRails::VERSION}' -m 'Version #{SoulmateRails::VERSION}'"
|
29
|
+
sh 'git push origin master --tags'
|
30
|
+
sh "gem push pkg/soulmate_rails-#{SoulmateRails::VERSION}.gem"
|
24
31
|
end
|
@@ -9,7 +9,7 @@ module SoulmateRails
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def update_index_for(attribute, options={})
|
12
|
-
loader = instance_variable_get("@#{
|
12
|
+
loader = instance_variable_get("@#{self.class.name_for(attribute)}_loader") || instance_variable_set("@#{self.class.name_for(attribute)}_loader", Soulmate::Loader.new(self.class.name_for(attribute)))
|
13
13
|
item = {
|
14
14
|
'id' => "#{attribute}_#{self.id}",
|
15
15
|
'term' => send(attribute),
|
@@ -35,18 +35,14 @@ module SoulmateRails
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
loader.add(item
|
38
|
+
loader.add(item)
|
39
39
|
end
|
40
40
|
|
41
41
|
def remove_index_for(attribute)
|
42
|
-
loader = instance_variable_get("@#{
|
42
|
+
loader = instance_variable_get("@#{self.class.name_for(attribute)}") || instance_variable_set("@#{self.class.name_for(attribute)}", Soulmate::Loader.new(self.class.name_for(attribute)))
|
43
43
|
loader.remove('id' => "#{attribute}_#{self.id}")
|
44
44
|
end
|
45
45
|
|
46
|
-
def loader_for(attribute)
|
47
|
-
"#{self.class.normalized_class_name}_#{attribute}"
|
48
|
-
end
|
49
|
-
|
50
46
|
module ClassMethods
|
51
47
|
def autocomplete(attribute, options={})
|
52
48
|
define_method "update_index_for_#{attribute}" do
|
@@ -66,16 +62,19 @@ module SoulmateRails
|
|
66
62
|
end
|
67
63
|
|
68
64
|
def search_by(attribute, term, options={})
|
69
|
-
matcher = instance_variable_get("@#{
|
65
|
+
matcher = instance_variable_get("@#{name_for(attribute)}_matcher") || instance_variable_set("@#{name_for(attribute)}_matcher", Soulmate::Matcher.new(name_for(attribute)))
|
70
66
|
matches = matcher.matches_for_term(term, options)
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
|
68
|
+
hash = {}
|
69
|
+
matches.each {|m| hash[m['id'].split('_')[-1].to_i] = m}
|
70
|
+
|
71
|
+
where(:id => hash.keys).map do |object|
|
72
|
+
object.soulmate_data = hash[object.id]['data'].symbolize_keys if hash[object.id] && hash[object.id]['data']
|
74
73
|
object
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
|
-
def
|
77
|
+
def name_for(attribute)
|
79
78
|
"#{normalized_class_name}_#{attribute}"
|
80
79
|
end
|
81
80
|
|
@@ -1,10 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'samples/models/user_single'
|
4
|
-
require 'samples/models/user_multiple'
|
5
|
-
require 'samples/models/user_aliases'
|
6
|
-
require 'samples/models/user_data'
|
7
|
-
|
8
3
|
module SoulmateRails
|
9
4
|
describe ModelAdditions do
|
10
5
|
context 'autocomplete for name' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
+
require 'rspec'
|
1
2
|
require 'supermodel'
|
2
3
|
require 'mock_redis'
|
3
4
|
require 'soulmate_rails'
|
4
5
|
|
6
|
+
require 'samples/models/user_single'
|
7
|
+
require 'samples/models/user_multiple'
|
8
|
+
require 'samples/models/user_aliases'
|
9
|
+
require 'samples/models/user_data'
|
10
|
+
|
5
11
|
TestRoot = File.expand_path(File.dirname(__FILE__))
|
6
12
|
|
7
13
|
RSpec.configure do |config|
|
8
14
|
config.order = 'random'
|
9
15
|
config.color_enabled = true
|
10
16
|
|
11
|
-
config.before(:
|
17
|
+
config.before(:suite) do
|
12
18
|
redis = MockRedis.new
|
13
19
|
redis.flushdb
|
14
20
|
Soulmate.redis = redis
|
15
21
|
end
|
16
22
|
end
|
17
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soulmate_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -172,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
segments:
|
174
174
|
- 0
|
175
|
-
hash: -
|
175
|
+
hash: -1107948345985026072
|
176
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
177
|
none: false
|
178
178
|
requirements:
|
@@ -181,10 +181,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
segments:
|
183
183
|
- 0
|
184
|
-
hash: -
|
184
|
+
hash: -1107948345985026072
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 1.8.
|
187
|
+
rubygems_version: 1.8.23
|
188
188
|
signing_key:
|
189
189
|
specification_version: 3
|
190
190
|
summary: Redis-backed autocompletion engine for Rails
|