recommendable 2.2.1 → 2.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bed9eb66adf5e636014b2f559c0f0c68542c778437bc177dfd4ce107fd7cbead
4
- data.tar.gz: e37871a3954bc1032249c6b5920193cddd0897f340d0fc9bda9f9ffd4ca761e3
3
+ metadata.gz: 47774cd75a72e1b2b326d535fc8dd5899481191dead0b71c0ced41d8f41ad81f
4
+ data.tar.gz: 117743d3c8bd0b1a5d217f16f35a2e101c2e56da5a6400ad128c2d6b00427d08
5
5
  SHA512:
6
- metadata.gz: ff226a0223b80b733d4ea0ff04805c343e9d4e6baa9376c1f5fb07ffab69559030ae0fe9a3680f6883c0991aed2073cd296ada67a1446132ba7e5dac9f318df9
7
- data.tar.gz: 9c3e92781cb02678ca928bfe66637071c38ddd14fc41936374235f22227b7030d0691232a99fa71e94f529ccbbf4bde73ea8ec79484e8303d3ef6b6e543e5563
6
+ metadata.gz: be8f704d0b9cc3329573da17d526f0c07bb5a27ee1792ca1446956850eb556b8b0fb9b4f12d964d9a8999157123d4f75c5b771c4184b452169754e1d4f71c20d
7
+ data.tar.gz: b4665e65e201f8d7f742792be24a92cbc347d296abaa95db07bbc080e468db4e7c53889722c4d034dcc512cd1f41943a28d269cc728e77c26bd90bbec1692e4a
@@ -43,11 +43,13 @@ module Recommendable
43
43
 
44
44
  # Query for the top-N items sorted by score
45
45
  #
46
- # @param [Fixnum] count the number of items to fetch (defaults to 1)
46
+ # @param [Hash] options a hash of options to modify which items are returned
47
+ # @option options [Integer] :count the number of items to fetch (defaults to 1)
48
+ # @option options [Integer] :offset an offset to allow paging through results
47
49
  # @return [Array] the top items belonging to this class, sorted by score
48
50
  def self.top(options = {})
49
51
  if options.is_a?(Integer)
50
- options = { :count => options}
52
+ options = { :count => options }
51
53
  warn "[DEPRECATION] Recommenable::Ratable.top now takes an options hash. Please call `.top(count: #{options[:count]})` instead of just `.top(#{options[:count]})`"
52
54
  end
53
55
  options.reverse_merge!(:count => 1, :offset => 0)
@@ -8,8 +8,9 @@ module Recommendable
8
8
  # @return [Array] An array of instances of your user class
9
9
  def similar_raters(limit = 10, offset = 0)
10
10
  ids = Recommendable.redis.zrevrange(Recommendable::Helpers::RedisKeyMapper.similarity_set_for(id), 0, -1)
11
+ ids = sanitize_ids(ids, self.class)
11
12
 
12
- order = ids.map { |id| "#{Recommendable.config.user_class.quoted_table_name}.#{Recommendable.config.user_class.quoted_primary_key} = %d DESC" }.join(', ')
13
+ order = ids.map { |id| "#{Recommendable.config.user_class.quoted_table_name}.#{Recommendable.config.user_class.quoted_primary_key} = ? DESC" }.join(', ')
13
14
  order = self.class.send(:sanitize_sql_for_assignment, [order, *ids])
14
15
 
15
16
  Recommendable.query(self.class, ids).order(order).limit(limit).offset(offset)
@@ -26,14 +27,21 @@ module Recommendable
26
27
 
27
28
  ids = Recommendable.redis.zrevrange(recommended_set, 0, -1, :with_scores => true)
28
29
  ids = ids.select { |id, score| score > 0 }.map { |pair| pair.first }
30
+ ids = sanitize_ids(ids, klass)
29
31
 
30
- order = ids.map { |id| "#{klass.quoted_table_name}.#{klass.quoted_primary_key} = %d DESC" }.join(', ')
32
+ order = ids.map { |id| "#{klass.quoted_table_name}.#{klass.quoted_primary_key} = ? DESC" }.join(', ')
31
33
  order = klass.send(:sanitize_sql_for_assignment, [order, *ids])
32
34
  Recommendable.query(klass, ids).order(order).limit(limit).offset(offset)
33
35
  end
34
36
 
35
37
  private
36
38
 
39
+ # Sanitizes ids using klass type mapping
40
+ # @private
41
+ def sanitize_ids(ids, klass)
42
+ ids.map{ |id| klass.new(klass.primary_key => id).send(klass.primary_key) }.compact
43
+ end
44
+
37
45
  # Removes an item from a user's set of recommendations
38
46
  # @private
39
47
  def unrecommend(obj)
@@ -2,7 +2,7 @@ module Recommendable
2
2
  class Version
3
3
  MAJOR = 2
4
4
  MINOR = 2
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recommendable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Celis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-15 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport