mongoid-slug 6.0.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +20 -20
  3. data/README.md +392 -336
  4. data/lib/mongoid/slug/criteria.rb +111 -107
  5. data/lib/mongoid/slug/{index.rb → index_builder.rb} +69 -45
  6. data/lib/mongoid/slug/railtie.rb +11 -9
  7. data/lib/mongoid/slug/slug_id_strategy.rb +5 -3
  8. data/lib/mongoid/slug/unique_slug.rb +172 -173
  9. data/lib/mongoid/slug/version.rb +7 -5
  10. data/lib/mongoid/slug.rb +333 -328
  11. data/lib/mongoid_slug.rb +4 -2
  12. data/lib/tasks/mongoid_slug.rake +17 -19
  13. metadata +13 -173
  14. data/spec/models/alias.rb +0 -6
  15. data/spec/models/article.rb +0 -9
  16. data/spec/models/artist.rb +0 -8
  17. data/spec/models/artwork.rb +0 -10
  18. data/spec/models/author.rb +0 -15
  19. data/spec/models/author_polymorphic.rb +0 -15
  20. data/spec/models/book.rb +0 -12
  21. data/spec/models/book_polymorphic.rb +0 -12
  22. data/spec/models/caption.rb +0 -17
  23. data/spec/models/entity.rb +0 -11
  24. data/spec/models/friend.rb +0 -7
  25. data/spec/models/incorrect_slug_persistence.rb +0 -9
  26. data/spec/models/integer_id.rb +0 -9
  27. data/spec/models/magazine.rb +0 -7
  28. data/spec/models/page.rb +0 -9
  29. data/spec/models/page_localize.rb +0 -9
  30. data/spec/models/page_slug_localized.rb +0 -9
  31. data/spec/models/page_slug_localized_custom.rb +0 -10
  32. data/spec/models/page_slug_localized_history.rb +0 -9
  33. data/spec/models/partner.rb +0 -7
  34. data/spec/models/person.rb +0 -12
  35. data/spec/models/relationship.rb +0 -8
  36. data/spec/models/string_id.rb +0 -9
  37. data/spec/models/subject.rb +0 -7
  38. data/spec/models/without_slug.rb +0 -5
  39. data/spec/mongoid/criteria_spec.rb +0 -207
  40. data/spec/mongoid/index_spec.rb +0 -33
  41. data/spec/mongoid/slug_spec.rb +0 -1169
  42. data/spec/shared/indexes.rb +0 -41
  43. data/spec/spec_helper.rb +0 -61
  44. data/spec/tasks/mongoid_slug_rake_spec.rb +0 -73
data/lib/mongoid_slug.rb CHANGED
@@ -1,2 +1,4 @@
1
- # To be removed
2
- require 'mongoid/slug'
1
+ # frozen_string_literal: true
2
+
3
+ # To be removed
4
+ require 'mongoid/slug'
@@ -1,19 +1,17 @@
1
- namespace :mongoid_slug do
2
- desc 'Goes though all documents and sets slug if not already set'
3
- task set: :environment do |_, args|
4
- ::Rails.application.eager_load! if defined?(Rails)
5
- klasses = Module.constants.find_all do |const|
6
- next if const == :MissingSourceFile
7
- const != const.upcase ? Mongoid::Slug > (Object.const_get const) : nil
8
- end
9
- klasses.map! { |klass| klass.to_s.constantize }
10
- unless klasses.blank?
11
- models = args.extras
12
- klasses = (klasses.map(&:to_s) & models.map(&:classify)).map(&:constantize) if models.any?
13
- klasses.each do |klass|
14
- # set slug for objects having blank slug
15
- klass.each { |object| object.set_slug! unless object.slugs? && object.slugs.any? }
16
- end
17
- end
18
- end
19
- end
1
+ # frozen_string_literal: true
2
+
3
+ namespace :mongoid_slug do
4
+ desc 'Goes though all documents and sets slug if not already set'
5
+ task set: :environment do |_, args|
6
+ Rails.application.eager_load! if defined?(Rails)
7
+ klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) }
8
+ unless klasses.blank?
9
+ models = args.extras
10
+ klasses = (klasses.map(&:to_s) & models.map(&:classify)).map(&:constantize) if models.any?
11
+ klasses.each do |klass|
12
+ # set slug for objects having blank slug
13
+ klass.each { |object| object.set_slug! unless object.slugs? && object.slugs.any? }
14
+ end
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-slug
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Saebjoernsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-17 00:00:00.000000000 Z
11
+ date: 2023-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,28 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: mongoid-compatibility
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '7.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: stringex
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,90 +38,6 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: awesome_print
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rspec-its
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: uuid
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
41
  description: Mongoid URL slug or permalink generator
140
42
  email:
141
43
  - andy@cosemble.com
@@ -147,49 +49,19 @@ files:
147
49
  - README.md
148
50
  - lib/mongoid/slug.rb
149
51
  - lib/mongoid/slug/criteria.rb
150
- - lib/mongoid/slug/index.rb
52
+ - lib/mongoid/slug/index_builder.rb
151
53
  - lib/mongoid/slug/railtie.rb
152
54
  - lib/mongoid/slug/slug_id_strategy.rb
153
55
  - lib/mongoid/slug/unique_slug.rb
154
56
  - lib/mongoid/slug/version.rb
155
57
  - lib/mongoid_slug.rb
156
58
  - lib/tasks/mongoid_slug.rake
157
- - spec/models/alias.rb
158
- - spec/models/article.rb
159
- - spec/models/artist.rb
160
- - spec/models/artwork.rb
161
- - spec/models/author.rb
162
- - spec/models/author_polymorphic.rb
163
- - spec/models/book.rb
164
- - spec/models/book_polymorphic.rb
165
- - spec/models/caption.rb
166
- - spec/models/entity.rb
167
- - spec/models/friend.rb
168
- - spec/models/incorrect_slug_persistence.rb
169
- - spec/models/integer_id.rb
170
- - spec/models/magazine.rb
171
- - spec/models/page.rb
172
- - spec/models/page_localize.rb
173
- - spec/models/page_slug_localized.rb
174
- - spec/models/page_slug_localized_custom.rb
175
- - spec/models/page_slug_localized_history.rb
176
- - spec/models/partner.rb
177
- - spec/models/person.rb
178
- - spec/models/relationship.rb
179
- - spec/models/string_id.rb
180
- - spec/models/subject.rb
181
- - spec/models/without_slug.rb
182
- - spec/mongoid/criteria_spec.rb
183
- - spec/mongoid/index_spec.rb
184
- - spec/mongoid/slug_spec.rb
185
- - spec/shared/indexes.rb
186
- - spec/spec_helper.rb
187
- - spec/tasks/mongoid_slug_rake_spec.rb
188
59
  homepage: https://github.com/mongoid/mongoid-slug
189
60
  licenses:
190
61
  - MIT
191
- metadata: {}
192
- post_install_message:
62
+ metadata:
63
+ rubygems_mfa_required: 'true'
64
+ post_install_message:
193
65
  rdoc_options: []
194
66
  require_paths:
195
67
  - lib
@@ -197,47 +69,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
69
  requirements:
198
70
  - - ">="
199
71
  - !ruby/object:Gem::Version
200
- version: '0'
72
+ version: '2.7'
201
73
  required_rubygems_version: !ruby/object:Gem::Requirement
202
74
  requirements:
203
75
  - - ">="
204
76
  - !ruby/object:Gem::Version
205
77
  version: '0'
206
78
  requirements: []
207
- rubyforge_project: mongoid-slug
208
- rubygems_version: 2.7.6
209
- signing_key:
79
+ rubygems_version: 3.4.4
80
+ signing_key:
210
81
  specification_version: 4
211
82
  summary: Mongoid URL slugs
212
- test_files:
213
- - spec/mongoid/criteria_spec.rb
214
- - spec/mongoid/slug_spec.rb
215
- - spec/mongoid/index_spec.rb
216
- - spec/spec_helper.rb
217
- - spec/tasks/mongoid_slug_rake_spec.rb
218
- - spec/shared/indexes.rb
219
- - spec/models/article.rb
220
- - spec/models/integer_id.rb
221
- - spec/models/book.rb
222
- - spec/models/entity.rb
223
- - spec/models/caption.rb
224
- - spec/models/without_slug.rb
225
- - spec/models/artist.rb
226
- - spec/models/string_id.rb
227
- - spec/models/page.rb
228
- - spec/models/page_slug_localized.rb
229
- - spec/models/author.rb
230
- - spec/models/friend.rb
231
- - spec/models/subject.rb
232
- - spec/models/magazine.rb
233
- - spec/models/partner.rb
234
- - spec/models/alias.rb
235
- - spec/models/person.rb
236
- - spec/models/page_slug_localized_custom.rb
237
- - spec/models/relationship.rb
238
- - spec/models/book_polymorphic.rb
239
- - spec/models/page_slug_localized_history.rb
240
- - spec/models/author_polymorphic.rb
241
- - spec/models/incorrect_slug_persistence.rb
242
- - spec/models/page_localize.rb
243
- - spec/models/artwork.rb
83
+ test_files: []
data/spec/models/alias.rb DELETED
@@ -1,6 +0,0 @@
1
- class Alias
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name, as: :author_name
5
- slug :author_name
6
- end
@@ -1,9 +0,0 @@
1
- class Article
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :brief
5
- field :title
6
- slug :title, :brief do |doc|
7
- [doc.title, doc.brief].reject(&:blank?).first
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- class Artist
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- slug :name
6
- field :name
7
- has_and_belongs_to_many :artworks
8
- end
@@ -1,10 +0,0 @@
1
- class Artwork
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- slug :title
6
- field :title
7
- field :published, type: Boolean, default: true
8
- scope :published, -> { where(published: true) }
9
- has_and_belongs_to_many :artists
10
- end
@@ -1,15 +0,0 @@
1
- class Author
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :first_name
5
- field :last_name
6
- if Mongoid::Compatibility::Version.mongoid6_or_newer?
7
- belongs_to :book, required: false
8
- else
9
- belongs_to :book
10
- end
11
- has_many :characters,
12
- class_name: 'Person',
13
- foreign_key: :author_id
14
- slug :first_name, :last_name, scope: :book, history: false, max_length: 256
15
- end
@@ -1,15 +0,0 @@
1
- class AuthorPolymorphic
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :first_name
5
- field :last_name
6
- slug :first_name, :last_name, scope: :book_polymorphic
7
- if Mongoid::Compatibility::Version.mongoid6_or_newer?
8
- belongs_to :book_polymorphic, required: false
9
- else
10
- belongs_to :book_polymorphic
11
- end
12
- has_many :characters,
13
- class_name: 'Person',
14
- foreign_key: :author_id
15
- end
data/spec/models/book.rb DELETED
@@ -1,12 +0,0 @@
1
- class Book
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title
5
-
6
- slug :title, history: true, max_length: nil
7
- embeds_many :subjects
8
- has_many :authors
9
- end
10
-
11
- class ComicBook < Book
12
- end
@@ -1,12 +0,0 @@
1
- class BookPolymorphic
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title
5
-
6
- slug :title, history: true, by_model_type: true
7
- embeds_many :subjects
8
- has_many :author_polymorphics
9
- end
10
-
11
- class ComicBookPolymorphic < BookPolymorphic
12
- end
@@ -1,17 +0,0 @@
1
- class Caption
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :my_identity, type: String
5
- field :title
6
- field :medium
7
-
8
- # A fairly complex scenario, where we want to create a slug out of an
9
- # my_identity field, which comprises name of artist and some more bibliographic
10
- # info in parantheses, and the title of the work.
11
- #
12
- # We are only interested in the name of the artist so we remove the
13
- # paranthesized details.
14
- slug :my_identity, :title do |cur_object|
15
- cur_object.slug_builder.gsub(/\s*\([^)]+\)/, '').to_url
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- class Entity
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- field :_id, type: String, slug_id_strategy: UuidIdStrategy
6
-
7
- field :name
8
- field :user_edited_variation
9
-
10
- slug :user_edited_variation, history: true
11
- end
@@ -1,7 +0,0 @@
1
- class Friend
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name
5
- field :slug_history, type: Array
6
- slug :name, reserve: ['foo', 'bar', /^[a-z]{2}$/i], history: true
7
- end
@@ -1,9 +0,0 @@
1
- class IncorrectSlugPersistence
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- field :name
6
- slug :name, history: true
7
-
8
- validates_length_of :name, minimum: 4, maximum: 5, allow_blank: true
9
- end
@@ -1,9 +0,0 @@
1
- class IntegerId
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- field :_id, type: Integer
6
- field :name, type: String
7
-
8
- slug :name, history: true
9
- end
@@ -1,7 +0,0 @@
1
- class Magazine
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title
5
- field :publisher_id
6
- slug :title, scope: :publisher_id
7
- end
data/spec/models/page.rb DELETED
@@ -1,9 +0,0 @@
1
- class Page
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title
5
- field :content
6
- field :order, type: Integer
7
- slug :title
8
- default_scope -> { asc(:order) }
9
- end
@@ -1,9 +0,0 @@
1
- class PageLocalize
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title, localize: true
5
- field :content
6
- field :order, type: Integer
7
- slug :title
8
- default_scope -> { asc(:order) }
9
- end
@@ -1,9 +0,0 @@
1
- class PageSlugLocalized
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title, localize: true
5
- field :content
6
- field :order, type: Integer
7
- slug :title, localize: true
8
- default_scope -> { asc(:order) }
9
- end
@@ -1,10 +0,0 @@
1
- class PageSlugLocalizedCustom
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- attr_accessor :title
6
-
7
- slug :title, localize: true do |obj|
8
- obj.title.to_url
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class PageSlugLocalizedHistory
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :title, localize: true
5
- field :content
6
- field :order, type: Integer
7
- slug :title, localize: true, history: true
8
- default_scope -> { asc(:order) }
9
- end
@@ -1,7 +0,0 @@
1
- class Partner
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name
5
- slug :name
6
- embedded_in :relationship
7
- end
@@ -1,12 +0,0 @@
1
- class Person
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name
5
- slug :name, permanent: true, scope: :author
6
- embeds_many :relationships
7
- if Mongoid::Compatibility::Version.mongoid6_or_newer?
8
- belongs_to :author, inverse_of: :characters, required: false
9
- else
10
- belongs_to :author, inverse_of: :characters
11
- end
12
- end
@@ -1,8 +0,0 @@
1
- class Relationship
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name
5
- slug :name
6
- embeds_many :partners
7
- embedded_in :person
8
- end
@@ -1,9 +0,0 @@
1
- class StringId
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
-
5
- field :_id, type: String
6
- field :name, type: String
7
-
8
- slug :name, history: true
9
- end
@@ -1,7 +0,0 @@
1
- class Subject
2
- include Mongoid::Document
3
- include Mongoid::Slug
4
- field :name
5
- slug :name, scope: :book, history: true
6
- embedded_in :book
7
- end
@@ -1,5 +0,0 @@
1
- class WithoutSlug
2
- include Mongoid::Document
3
-
4
- field :_id, type: Integer
5
- end