soulmate_rails 0.2.1 → 0.3.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/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.3@soulmate_rails --create
1
+ rvm 1.9.3-p385@soulmate_rails --create
data/Gemfile CHANGED
@@ -1,2 +1,6 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
+
4
+ group :development do
5
+ gem 'supermodel', :git => 'git@github.com:dhruvasagar/supermodel.git'
6
+ end
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("@#{loader_for(attribute)}") || instance_variable_set("@#{loader_for(attribute)}", Soulmate::Loader.new(loader_for(attribute)))
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, options)
38
+ loader.add(item)
39
39
  end
40
40
 
41
41
  def remove_index_for(attribute)
42
- loader = instance_variable_get("@#{loader_for(attribute)}") || instance_variable_set("@#{loader_for(attribute)}", Soulmate::Loader.new(loader_for(attribute)))
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("@#{matcher_for(attribute)}") || instance_variable_set("@#{matcher_for(attribute)}", Soulmate::Matcher.new(matcher_for(attribute)))
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
- matches = matches.map do |match|
72
- object = find(match['id'].split('_')[-1].to_i)
73
- object.soulmate_data = match['data'].symbolize_keys if object && match['data']
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 matcher_for(attribute)
77
+ def name_for(attribute)
79
78
  "#{normalized_class_name}_#{attribute}"
80
79
  end
81
80
 
@@ -1,7 +1,7 @@
1
1
  module SoulmateRails
2
2
  MAJOR = 0
3
- MINOR = 2
4
- PATCH = 1
3
+ MINOR = 3
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -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(:each) do
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.2.1
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-03-05 00:00:00.000000000 Z
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: -4388796581995930831
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: -4388796581995930831
184
+ hash: -1107948345985026072
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 1.8.25
187
+ rubygems_version: 1.8.23
188
188
  signing_key:
189
189
  specification_version: 3
190
190
  summary: Redis-backed autocompletion engine for Rails