mongoid-slug 6.0.1 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -3
- data/lib/mongoid/slug/criteria.rb +10 -6
- data/lib/mongoid/slug/index_builder.rb +2 -0
- data/lib/mongoid/slug/railtie.rb +2 -0
- data/lib/mongoid/slug/slug_id_strategy.rb +2 -0
- data/lib/mongoid/slug/unique_slug.rb +8 -9
- data/lib/mongoid/slug/version.rb +4 -2
- data/lib/mongoid/slug.rb +15 -10
- data/lib/mongoid_slug.rb +2 -0
- data/lib/tasks/mongoid_slug.rake +3 -1
- metadata +9 -168
- data/spec/models/alias.rb +0 -6
- data/spec/models/article.rb +0 -9
- data/spec/models/artist.rb +0 -8
- data/spec/models/artwork.rb +0 -10
- data/spec/models/author.rb +0 -15
- data/spec/models/author_polymorphic.rb +0 -15
- data/spec/models/book.rb +0 -12
- data/spec/models/book_polymorphic.rb +0 -12
- data/spec/models/caption.rb +0 -17
- data/spec/models/entity.rb +0 -11
- data/spec/models/friend.rb +0 -7
- data/spec/models/incorrect_slug_persistence.rb +0 -9
- data/spec/models/integer_id.rb +0 -9
- data/spec/models/magazine.rb +0 -7
- data/spec/models/page.rb +0 -9
- data/spec/models/page_localize.rb +0 -9
- data/spec/models/page_slug_localized.rb +0 -9
- data/spec/models/page_slug_localized_custom.rb +0 -10
- data/spec/models/page_slug_localized_history.rb +0 -9
- data/spec/models/partner.rb +0 -7
- data/spec/models/person.rb +0 -12
- data/spec/models/relationship.rb +0 -8
- data/spec/models/string_id.rb +0 -9
- data/spec/models/subject.rb +0 -7
- data/spec/models/without_slug.rb +0 -5
- data/spec/mongoid/criteria_spec.rb +0 -207
- data/spec/mongoid/index_builder_spec.rb +0 -105
- data/spec/mongoid/slug_spec.rb +0 -1175
- data/spec/shared/indexes.rb +0 -41
- data/spec/spec_helper.rb +0 -61
- data/spec/tasks/mongoid_slug_rake_spec.rb +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 316ca3607617c4e0c9f74a98fcac1d1629e5d777b79d6b4dab5a3ed3d07b3989
|
4
|
+
data.tar.gz: c55bbfa991bdc760e461b8ab73de8deb972bcbf784bc2db37640a1d03a5e51aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4cbe88440e9ef769c7fb91f1a2fed9e294b2cb213e0779425314b4bfc20307d0003688f3ee7ce00bc2c34560f99fda420b038179b5f919a22ddfcd3559ebab5
|
7
|
+
data.tar.gz: d89e83169fe6e282a664b0ffa2db13d7235e413d39a25948142c85aa21ef830c298663d77364b3590c48e4b6a736e1b3b279681030a6de9c920ede6f8411aadb
|
data/README.md
CHANGED
@@ -8,6 +8,12 @@ It sits idly on top of [stringex](https://github.com/rsl/stringex), supporting n
|
|
8
8
|
[![Gem Version](https://badge.fury.io/rb/mongoid-slug.svg)](http://badge.fury.io/rb/mongoid-slug)
|
9
9
|
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-slug.svg)](https://codeclimate.com/github/mongoid/mongoid-slug)
|
10
10
|
|
11
|
+
### Version Support
|
12
|
+
|
13
|
+
Mongoid Slug 7.x requires at least Mongoid 7.0.0 and Ruby 2.7.0. For earlier Mongoid and Ruby version support, please use an earlier version of Mongoid Slug.
|
14
|
+
|
15
|
+
Mongoid Slug is compatible with all MongoDB versions which Mongoid supports, however, please see "Slug Max Length" section below for MongoDB 4.0 and earlier.
|
16
|
+
|
11
17
|
### Installation
|
12
18
|
|
13
19
|
Add to your Gemfile:
|
@@ -70,6 +76,7 @@ post = Post.find 'a-thousand-plateaus' # Finds by slugs
|
|
70
76
|
post = Post.find '50b1386a0482939864000001' # Finds by bson ids
|
71
77
|
=> ...
|
72
78
|
```
|
79
|
+
|
73
80
|
[Examine slug.rb](lib/mongoid/slug.rb) for all available options.
|
74
81
|
|
75
82
|
### Updating Existing Records
|
@@ -127,6 +134,23 @@ The `to_url` method comes from [stringex](https://github.com/rsl/stringex).
|
|
127
134
|
|
128
135
|
You can define a slug builder globally and/or override it per model.
|
129
136
|
|
137
|
+
### Indexing
|
138
|
+
|
139
|
+
By default, Mongoid Slug will automatically generate an index for the slug, which will be created when you run `rake db:create_indexes`. This index will take into account scoping and other options described below.
|
140
|
+
|
141
|
+
To skip this index generation, you may set `index: false` as follows:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
class Employee
|
145
|
+
include Mongoid::Document
|
146
|
+
include Mongoid::Slug
|
147
|
+
|
148
|
+
field :name
|
149
|
+
|
150
|
+
slug :name, index: :false
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
130
154
|
### Scoping
|
131
155
|
|
132
156
|
To scope a slug by a reference association, pass `:scope`:
|
@@ -169,9 +193,16 @@ class Employee
|
|
169
193
|
end
|
170
194
|
```
|
171
195
|
|
172
|
-
###
|
196
|
+
### Slug Max Length
|
173
197
|
|
174
|
-
MongoDB
|
198
|
+
MongoDB [featureCompatibilityVersion](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv)
|
199
|
+
"4.0" and earlier applies an [Index Key Limit](https://docs.mongodb.com/manual/reference/limits/#mongodb-limit-Index-Key-Limit)
|
200
|
+
which limits the total size of an index entry to around 1KB and will raise error,
|
201
|
+
`17280 - key too large to index` when trying to create a record that causes an index key to exceed that limit.
|
202
|
+
By default slugs are of the form `text[-number]` and the text portion is limited in size
|
203
|
+
to `Mongoid::Slug::MONGO_INDEX_KEY_LIMIT_BYTES - 32` bytes.
|
204
|
+
You can change this limit with `max_length` or set it to `nil` if you're running MongoDB
|
205
|
+
with [failIndexKeyTooLong](https://docs.mongodb.org/manual/reference/parameters/#param.failIndexKeyTooLong) set to `false`.
|
175
206
|
|
176
207
|
```ruby
|
177
208
|
class Company
|
@@ -295,7 +326,7 @@ For example, if `I18n.default_locale` is `:en`, the index will be generated as f
|
|
295
326
|
```ruby
|
296
327
|
slug :title, localize: true
|
297
328
|
|
298
|
-
# The following
|
329
|
+
# The following index is auto-generated:
|
299
330
|
index({ '_slugs.en' => 1 }, { unique: true, sparse: true })
|
300
331
|
```
|
301
332
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mongoid
|
2
4
|
module Slug
|
3
5
|
class Criteria < Mongoid::Criteria
|
@@ -50,6 +52,7 @@ module Mongoid
|
|
50
52
|
|
51
53
|
def look_like_slugs?(args)
|
52
54
|
return false unless args.all? { |id| id.is_a?(String) }
|
55
|
+
|
53
56
|
id_field = @klass.fields['_id']
|
54
57
|
@slug_strategy ||= id_field.options[:slug_id_strategy] || build_slug_strategy(id_field.type)
|
55
58
|
args.none? { |id| @slug_strategy.call(id) }
|
@@ -61,13 +64,13 @@ module Mongoid
|
|
61
64
|
# use object_id or string strategy depending on the id_type
|
62
65
|
# otherwise default for all other id_types
|
63
66
|
def build_slug_strategy(id_type)
|
64
|
-
type_method = id_type.to_s.downcase.split('::').last
|
67
|
+
type_method = "#{id_type.to_s.downcase.split('::').last}_slug_strategy"
|
65
68
|
respond_to?(type_method, true) ? method(type_method) : ->(_id) { false }
|
66
69
|
end
|
67
70
|
|
68
71
|
# a string will not look like a slug if it looks like a legal BSON::ObjectId
|
69
72
|
def objectid_slug_strategy(id)
|
70
|
-
|
73
|
+
BSON::ObjectId.legal?(id)
|
71
74
|
end
|
72
75
|
|
73
76
|
# a string will always look like a slug
|
@@ -78,10 +81,10 @@ module Mongoid
|
|
78
81
|
def for_slugs(slugs)
|
79
82
|
# _translations
|
80
83
|
localized = (begin
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
@klass.fields['_slugs'].options[:localize]
|
85
|
+
rescue StandardError
|
86
|
+
false
|
87
|
+
end)
|
85
88
|
if localized
|
86
89
|
def_loc = I18n.default_locale
|
87
90
|
query = { '$in' => slugs }
|
@@ -100,6 +103,7 @@ module Mongoid
|
|
100
103
|
def check_for_missing_documents_for_slugs!(result, slugs)
|
101
104
|
missing_slugs = slugs - result.map(&:slugs).flatten
|
102
105
|
return unless !missing_slugs.blank? && Mongoid.raise_not_found_error
|
106
|
+
|
103
107
|
raise Errors::DocumentNotFound.new(klass, slugs, missing_slugs)
|
104
108
|
end
|
105
109
|
end
|
data/lib/mongoid/slug/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
# Can use e.g. Mongoid::Slug::UniqueSlug.new(ModelClass.new).find_unique "slug-1" for auto-suggest ui
|
@@ -20,9 +22,10 @@ module Mongoid
|
|
20
22
|
@documents.each do |doc|
|
21
23
|
history_slugs = doc._slugs
|
22
24
|
next if history_slugs.nil?
|
23
|
-
|
25
|
+
|
26
|
+
existing_slugs.push(*history_slugs.grep(regexp_pattern))
|
24
27
|
last_entered_slug.push(*history_slugs.last) if history_slugs.last =~ regexp_pattern
|
25
|
-
existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).
|
28
|
+
existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).grep(regexp_pattern))
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -111,7 +114,7 @@ module Mongoid
|
|
111
114
|
@state.include_slug unless model.class.look_like_slugs?([@_slug])
|
112
115
|
|
113
116
|
# make sure that the slug is not equal to a reserved word
|
114
|
-
@state.include_slug if slug_reserved_words.any? { |word| word === @_slug }
|
117
|
+
@state.include_slug if slug_reserved_words.any? { |word| word === @_slug } # rubocop:disable Style/CaseEquality
|
115
118
|
|
116
119
|
# only look for a new unique slug if the existing slugs contains the current slug
|
117
120
|
# - e.g if the slug 'foo-2' is taken, but 'foo' is available, the user can use 'foo'.
|
@@ -132,7 +135,7 @@ module Mongoid
|
|
132
135
|
# index to match /^.../ pattern.
|
133
136
|
# Use Regexp::Raw to avoid the multiline option when querying the server.
|
134
137
|
def regex_for_slug
|
135
|
-
if embedded?
|
138
|
+
if embedded?
|
136
139
|
Regexp.new(escaped_pattern)
|
137
140
|
else
|
138
141
|
BSON::Regexp::Raw.new(escaped_pattern)
|
@@ -155,11 +158,7 @@ module Mongoid
|
|
155
158
|
end
|
156
159
|
|
157
160
|
if embedded?
|
158
|
-
parent_metadata =
|
159
|
-
reflect_on_all_association(:embedded_in)[0]
|
160
|
-
else
|
161
|
-
reflect_on_all_associations(:embedded_in)[0]
|
162
|
-
end
|
161
|
+
parent_metadata = reflect_on_all_association(:embedded_in)[0]
|
163
162
|
return model._parent.send(parent_metadata.inverse_of || self.metadata.name)
|
164
163
|
end
|
165
164
|
|
data/lib/mongoid/slug/version.rb
CHANGED
data/lib/mongoid/slug.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mongoid'
|
2
4
|
require 'stringex'
|
3
5
|
require 'mongoid/slug/criteria'
|
4
6
|
require 'mongoid/slug/index_builder'
|
5
7
|
require 'mongoid/slug/unique_slug'
|
6
8
|
require 'mongoid/slug/slug_id_strategy'
|
7
|
-
require 'mongoid-compatibility'
|
8
9
|
require 'mongoid/slug/railtie' if defined?(Rails)
|
9
10
|
|
10
11
|
module Mongoid
|
@@ -17,6 +18,7 @@ module Mongoid
|
|
17
18
|
included do
|
18
19
|
cattr_accessor :slug_reserved_words,
|
19
20
|
:slug_scope,
|
21
|
+
:slug_index,
|
20
22
|
:slugged_attributes,
|
21
23
|
:slug_url_builder,
|
22
24
|
:slug_history,
|
@@ -29,6 +31,7 @@ module Mongoid
|
|
29
31
|
|
30
32
|
class << self
|
31
33
|
attr_accessor :default_slug
|
34
|
+
|
32
35
|
def configure(&block)
|
33
36
|
instance_eval(&block)
|
34
37
|
end
|
@@ -75,6 +78,7 @@ module Mongoid
|
|
75
78
|
options = fields.extract_options!
|
76
79
|
|
77
80
|
self.slug_scope = options[:scope]
|
81
|
+
self.slug_index = options[:index].nil? ? true : options[:index]
|
78
82
|
self.slug_reserved_words = options[:reserve] || Set.new(%w[new edit])
|
79
83
|
self.slugged_attributes = fields.map(&:to_s)
|
80
84
|
self.slug_history = options[:history]
|
@@ -85,7 +89,10 @@ module Mongoid
|
|
85
89
|
alias_attribute :slugs, :_slugs
|
86
90
|
|
87
91
|
# Set indexes
|
88
|
-
|
92
|
+
if slug_index && !embedded?
|
93
|
+
Mongoid::Slug::IndexBuilder.build_indexes(self, slug_scope_key, slug_by_model_type,
|
94
|
+
options[:localize])
|
95
|
+
end
|
89
96
|
|
90
97
|
self.slug_url_builder = block_given? ? block : default_slug_url_builder
|
91
98
|
|
@@ -111,6 +118,7 @@ module Mongoid
|
|
111
118
|
# @return [ Array<Document>, Document ]
|
112
119
|
def slug_scope_key
|
113
120
|
return nil unless slug_scope
|
121
|
+
|
114
122
|
reflect_on_association(slug_scope).try(:key) || slug_scope
|
115
123
|
end
|
116
124
|
|
@@ -141,17 +149,13 @@ module Mongoid
|
|
141
149
|
|
142
150
|
private
|
143
151
|
|
144
|
-
if
|
152
|
+
if Threaded.method(:current_scope).arity == -1
|
145
153
|
def current_scope
|
146
154
|
Threaded.current_scope(self)
|
147
155
|
end
|
148
|
-
elsif Mongoid::Compatibility::Version.mongoid5_or_newer?
|
149
|
-
def current_scope
|
150
|
-
Threaded.current_scope
|
151
|
-
end
|
152
156
|
else
|
153
157
|
def current_scope
|
154
|
-
|
158
|
+
Threaded.current_scope
|
155
159
|
end
|
156
160
|
end
|
157
161
|
end
|
@@ -181,10 +185,10 @@ module Mongoid
|
|
181
185
|
|
182
186
|
# skip slug generation and use Mongoid id
|
183
187
|
# to find document instead
|
184
|
-
return true if new_slug.
|
188
|
+
return true if new_slug.empty?
|
185
189
|
|
186
190
|
# avoid duplicate slugs
|
187
|
-
_slugs
|
191
|
+
_slugs&.delete(new_slug)
|
188
192
|
|
189
193
|
if !!slug_history && _slugs.is_a?(Array)
|
190
194
|
append_slug(new_slug)
|
@@ -249,6 +253,7 @@ module Mongoid
|
|
249
253
|
# @return [String] the slug, or nil if the document does not have a slug.
|
250
254
|
def slug
|
251
255
|
return _slugs.last if _slugs
|
256
|
+
|
252
257
|
_id.to_s
|
253
258
|
end
|
254
259
|
|
data/lib/mongoid_slug.rb
CHANGED
data/lib/tasks/mongoid_slug.rake
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
namespace :mongoid_slug do
|
2
4
|
desc 'Goes though all documents and sets slug if not already set'
|
3
5
|
task set: :environment do |_, args|
|
4
|
-
|
6
|
+
Rails.application.eager_load! if defined?(Rails)
|
5
7
|
klasses = Mongoid::Config.models.find_all { |c| c.ancestors.include?(Mongoid::Slug) }
|
6
8
|
unless klasses.blank?
|
7
9
|
models = args.extras
|
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:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Saebjoernsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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: '
|
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: '
|
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
|
@@ -154,41 +56,11 @@ files:
|
|
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_builder_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:
|
62
|
+
metadata:
|
63
|
+
rubygems_mfa_required: 'true'
|
192
64
|
post_install_message:
|
193
65
|
rdoc_options: []
|
194
66
|
require_paths:
|
@@ -197,46 +69,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
69
|
requirements:
|
198
70
|
- - ">="
|
199
71
|
- !ruby/object:Gem::Version
|
200
|
-
version: '
|
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
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.4.4
|
208
80
|
signing_key:
|
209
81
|
specification_version: 4
|
210
82
|
summary: Mongoid URL slugs
|
211
|
-
test_files:
|
212
|
-
- spec/models/alias.rb
|
213
|
-
- spec/models/article.rb
|
214
|
-
- spec/models/artist.rb
|
215
|
-
- spec/models/artwork.rb
|
216
|
-
- spec/models/author.rb
|
217
|
-
- spec/models/author_polymorphic.rb
|
218
|
-
- spec/models/book.rb
|
219
|
-
- spec/models/book_polymorphic.rb
|
220
|
-
- spec/models/caption.rb
|
221
|
-
- spec/models/entity.rb
|
222
|
-
- spec/models/friend.rb
|
223
|
-
- spec/models/incorrect_slug_persistence.rb
|
224
|
-
- spec/models/integer_id.rb
|
225
|
-
- spec/models/magazine.rb
|
226
|
-
- spec/models/page.rb
|
227
|
-
- spec/models/page_localize.rb
|
228
|
-
- spec/models/page_slug_localized.rb
|
229
|
-
- spec/models/page_slug_localized_custom.rb
|
230
|
-
- spec/models/page_slug_localized_history.rb
|
231
|
-
- spec/models/partner.rb
|
232
|
-
- spec/models/person.rb
|
233
|
-
- spec/models/relationship.rb
|
234
|
-
- spec/models/string_id.rb
|
235
|
-
- spec/models/subject.rb
|
236
|
-
- spec/models/without_slug.rb
|
237
|
-
- spec/mongoid/criteria_spec.rb
|
238
|
-
- spec/mongoid/index_builder_spec.rb
|
239
|
-
- spec/mongoid/slug_spec.rb
|
240
|
-
- spec/shared/indexes.rb
|
241
|
-
- spec/spec_helper.rb
|
242
|
-
- spec/tasks/mongoid_slug_rake_spec.rb
|
83
|
+
test_files: []
|
data/spec/models/alias.rb
DELETED
data/spec/models/article.rb
DELETED
data/spec/models/artist.rb
DELETED
data/spec/models/artwork.rb
DELETED
data/spec/models/author.rb
DELETED
@@ -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 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
|
data/spec/models/caption.rb
DELETED
@@ -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
|