similar_models 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b55aa8e2b833092a963b70b211ff10f0ee78ead0
4
- data.tar.gz: 264b408ebdb78c40b31a1c7f37c99cf6a0360c76
2
+ SHA256:
3
+ metadata.gz: 1c7c43faef16009cad0a971ec3afc6efc716bd77723d45395a70365e2a96fa9b
4
+ data.tar.gz: ac4deb962291c450f53cbf4731ada109ad3a505e009225dcae1f87495c817802
5
5
  SHA512:
6
- metadata.gz: b81bfa56e0a7cfad7ca1c2e3e00d67645dcf18ef2c0e1726d8f23905ffceda65e1ee7d8a617f5e1af136c62a36cb0f20b85f6e9cac5a5792423c06d277e812c6
7
- data.tar.gz: b2a2d671129e2bdc1498296b8ce299d599132f96751bb5227fa5a35458026b4fb6c13e01710a29502e047f0632a8484df506fbef0f29fb21e40cd85d11857652
6
+ metadata.gz: 228a426d2b7a8f10e0db47034e66a8f166ca957ef05e242fc787eeb2c84add141c4b4ba4b95a38f4eaa909cb13d69b8209db968d06b8f4d90ab46445828791c4
7
+ data.tar.gz: 3dfee9418bb74aaddc686f96be94a69073b395f7a9edeac5a7a6900044c70cb0386a2da7ac7b84aa69f8766bcb8eb8b12c6c303bbb4f55615846f610c7fa0b1c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 3.4.2
data/README.md CHANGED
@@ -8,73 +8,87 @@ The association(s) have to be many to many, so either [habtm](http://guides.ruby
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'similar_models'
11
+ ```sh
12
+ gem 'similar_models'
13
+ ```
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install similar_models
17
+ ```sh
18
+ $ bundle
19
+ ```
20
20
 
21
21
  ## Usage
22
22
 
23
23
  Post example
24
24
 
25
- class Post < ActiveRecord::Base
26
- has_many :author_posts
27
- has_many :authors, through: :author_posts
28
- has_and_belongs_to_many :tags
25
+ ```ruby
26
+ class Post < ActiveRecord::Base
27
+ has_many :author_posts
28
+ has_many :authors, through: :author_posts
29
+ has_and_belongs_to_many :tags
29
30
 
30
- has_similar_models :authors
31
- has_similar_models :tags, as: :similar_posts_by_tag
32
- has_similar_models :authors, :tags, as: :similar_posts_by_author_and_tag
33
- end
31
+ has_similar_models :authors
32
+ has_similar_models :tags, as: :similar_posts_by_tag
33
+ has_similar_models :authors, :tags, as: :similar_posts_by_author_and_tag
34
+ end
34
35
 
35
- class Tag < ActiveRecord::Base
36
- end
36
+ class Tag < ActiveRecord::Base
37
+ end
37
38
 
38
- class Author < ActiveRecord::Base
39
- has_many :author_posts
40
- end
39
+ class Author < ActiveRecord::Base
40
+ has_many :author_posts
41
+ end
41
42
 
42
- class AuthorPosts < ActiveRecord::Base
43
- belongs_to :author
44
- belongs_to :post
45
- end
43
+ class AuthorPosts < ActiveRecord::Base
44
+ belongs_to :author
45
+ belongs_to :post
46
+ end
47
+ ```
46
48
 
47
49
  To return the posts with the most authors in common with `post` in descending order:
48
50
 
49
- post.similar_posts
51
+ ```ruby
52
+ post.similar_posts
53
+ ```
50
54
 
51
55
  The returned object is an ActiveRecord::Relation and so chaining of other query methods is possible:
52
56
 
53
- post.similar_posts.where('posts.created_at > ?', 10.days.ago).limit(5)
57
+ ```ruby
58
+ post.similar_posts.where(posts.created_at: 10.days.ago..).limit(5)
59
+ ```
54
60
 
55
61
  To return the posts with the most tags in common with `post` in descending order:
56
62
 
57
- post.similar_posts_by_tag
63
+ ```ruby
64
+ post.similar_posts_by_tag
65
+ ```
58
66
 
59
67
  To return the posts with the most authors and tags in common with `post` in descending order:
60
68
 
61
- post.similar_posts_by_author_and_tag
69
+ ```ruby
70
+ post.similar_posts_by_author_and_tag
71
+ ```
62
72
 
63
73
  The count of the associated models in common is accessible on each returned model:
64
74
 
65
- post.similar_posts_model_count
66
- post.similar_posts_by_tag_model_count
67
- post.similar_posts_by_author_and_tag_model_count
75
+ ```ruby
76
+ post.similar_posts_model_count
77
+ post.similar_posts_by_tag_model_count
78
+ post.similar_posts_by_author_and_tag_model_count
79
+ ```
68
80
 
69
- Note multiple associations do not work with sqlite.
81
+ **Note multiple associations do not work with sqlite.**
70
82
 
71
83
  Because of the use of `group`, pagination is not supported.
72
84
 
73
85
  ## In conjunction with acts-as-taggable-on
74
86
 
75
- If you use https://github.com/mbleigh/acts-as-taggable-on/#usage and want to find related users say across multiple contexts:
87
+ If you use [mbleigh/acts-as-taggable-on](https://github.com/mbleigh/acts-as-taggable-on/#usage) and want to find related users say across multiple contexts:
76
88
 
77
- user.similar_users.where(taggings: { context: %w(skills interests) })
89
+ ```ruby
90
+ user.similar_users.where(taggings: { context: %w(skills interests) })
91
+ ```
78
92
 
79
93
  ## Contributing
80
94
 
@@ -1,3 +1,3 @@
1
1
  module SimilarModels
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -31,7 +31,6 @@ module SimilarModels
31
31
  if association_scopes.one?
32
32
  scope.merge(association_scopes.first).group(group_by_clause)
33
33
  else
34
- # see http://blog.ubersense.com/2013/09/27/tech-talk-unioning-scoped-queries-in-rails/
35
34
  scope.from("((#{association_scopes.map(&:to_sql).join(') UNION ALL (')})) AS #{table_name}").group(group_by_clause)
36
35
  end
37
36
  end
@@ -18,13 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = '>= 2.1'
22
- spec.add_runtime_dependency 'activerecord', '>= 4.2'
23
- spec.add_development_dependency 'bundler', '~> 1.16'
21
+ spec.required_ruby_version = '>= 3.1'
22
+ spec.add_runtime_dependency 'activerecord', '>= 7.2'
24
23
  spec.add_development_dependency 'rspec', '~> 3.5'
25
24
  spec.add_development_dependency 'database_cleaner', '~>1.5'
26
- spec.add_development_dependency 'sqlite3', '~>1.3'
25
+ spec.add_development_dependency 'sqlite3', '~>2.6'
27
26
  spec.add_development_dependency 'mysql2', '~>0.5'
28
- spec.add_development_dependency 'pg', '~>1.0'
29
- spec.add_development_dependency 'byebug', '~>9.0'
27
+ spec.add_development_dependency 'pg', '~>1.5'
28
+ spec.add_development_dependency 'debug', '~>1.0'
30
29
  end
data/spec/spec_helper.rb CHANGED
@@ -15,7 +15,7 @@ load 'support/schema.rb'
15
15
  require 'similar_models'
16
16
  require 'support/models'
17
17
  require 'database_cleaner'
18
- require 'byebug'
18
+ require 'debug'
19
19
 
20
20
  DatabaseCleaner.strategy = :transaction
21
21
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: similar_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jolyon Pawlyn
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-05-10 00:00:00.000000000 Z
10
+ date: 2025-02-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -16,28 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '4.2'
18
+ version: '7.2'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '4.2'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.16'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.16'
25
+ version: '7.2'
41
26
  - !ruby/object:Gem::Dependency
42
27
  name: rspec
43
28
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +57,14 @@ dependencies:
72
57
  requirements:
73
58
  - - "~>"
74
59
  - !ruby/object:Gem::Version
75
- version: '1.3'
60
+ version: '2.6'
76
61
  type: :development
77
62
  prerelease: false
78
63
  version_requirements: !ruby/object:Gem::Requirement
79
64
  requirements:
80
65
  - - "~>"
81
66
  - !ruby/object:Gem::Version
82
- version: '1.3'
67
+ version: '2.6'
83
68
  - !ruby/object:Gem::Dependency
84
69
  name: mysql2
85
70
  requirement: !ruby/object:Gem::Requirement
@@ -100,28 +85,28 @@ dependencies:
100
85
  requirements:
101
86
  - - "~>"
102
87
  - !ruby/object:Gem::Version
103
- version: '1.0'
88
+ version: '1.5'
104
89
  type: :development
105
90
  prerelease: false
106
91
  version_requirements: !ruby/object:Gem::Requirement
107
92
  requirements:
108
93
  - - "~>"
109
94
  - !ruby/object:Gem::Version
110
- version: '1.0'
95
+ version: '1.5'
111
96
  - !ruby/object:Gem::Dependency
112
- name: byebug
97
+ name: debug
113
98
  requirement: !ruby/object:Gem::Requirement
114
99
  requirements:
115
100
  - - "~>"
116
101
  - !ruby/object:Gem::Version
117
- version: '9.0'
102
+ version: '1.0'
118
103
  type: :development
119
104
  prerelease: false
120
105
  version_requirements: !ruby/object:Gem::Requirement
121
106
  requirements:
122
107
  - - "~>"
123
108
  - !ruby/object:Gem::Version
124
- version: '9.0'
109
+ version: '1.0'
125
110
  description: Adds an instance method to an active record model that returns the most
126
111
  similar models based on associated models in common
127
112
  email:
@@ -147,7 +132,6 @@ homepage: https://github.com/jpawlyn/similar_models
147
132
  licenses:
148
133
  - MIT
149
134
  metadata: {}
150
- post_install_message:
151
135
  rdoc_options: []
152
136
  require_paths:
153
137
  - lib
@@ -155,16 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
139
  requirements:
156
140
  - - ">="
157
141
  - !ruby/object:Gem::Version
158
- version: '2.1'
142
+ version: '3.1'
159
143
  required_rubygems_version: !ruby/object:Gem::Requirement
160
144
  requirements:
161
145
  - - ">="
162
146
  - !ruby/object:Gem::Version
163
147
  version: '0'
164
148
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.5.2
167
- signing_key:
149
+ rubygems_version: 3.6.5
168
150
  specification_version: 4
169
151
  summary: Returns models that have the most associated models in common
170
152
  test_files: