mongoid-slug 5.3.0 → 5.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bda81e5e78c0e83e9785ff87f5b6e1f6b4ca637a
4
- data.tar.gz: f89a8f074c6ac112b65a62b9a0e122cabaef1d54
3
+ metadata.gz: 1d893221f1b5a7c840e42c98a2f7e74d976b4381
4
+ data.tar.gz: 3b9afae74aab2d130496f3cf23a0811f85705047
5
5
  SHA512:
6
- metadata.gz: b30566749607cda56d2b4ed929327978f8997adca09a08a2f66b2b375a5f5485a9967c2c178bf7aa6433d78345d75b814a729f3c98e85f4195e81d1fe9880be8
7
- data.tar.gz: 37c91ae5d6984e3403123e7bab3e568cbce7540d002509d5d3bfa396fd2fc72f8d8096498c933dae180aceec8f5edc09fda6e4a5fe1b9c0bbb1a40ed935ce76f
6
+ metadata.gz: 237ffaf248bd69f1dd9927554d2ab2d6bbcd16bfffaae685fee3cbcb07f084bbe8763ccd3dc85c9d46c659179ddf9d9d0fb25127127effee78015a561260363c
7
+ data.tar.gz: ea089ee25f529cb8c18c206eaf3f7566668e1c788f4c0cd4e6bc7c0f381728ac8986c7e8695b8a90078a751c75fb77b80e578b1860a1e2da574b3639d2627ae1
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2016 Hakan Ensari & Contributors
1
+ Copyright (c) 2010-2017 Hakan Ensari & Contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,7 +1,7 @@
1
1
  module Mongoid
2
2
  module Slug
3
3
  class Criteria < Mongoid::Criteria
4
- # Find the matchind document(s) in the criteria for the provided ids or slugs.
4
+ # Find the matching document(s) in the criteria for the provided ids or slugs.
5
5
  #
6
6
  # If the document _ids are of the type BSON::ObjectId, and all the supplied parameters are
7
7
  # convertible to BSON::ObjectId (via BSON::ObjectId#from_string), finding will be
@@ -16,12 +16,13 @@ module Mongoid
16
16
  @existing_slugs = []
17
17
  @existing_history_slugs = []
18
18
  @sorted_existing = []
19
+ regexp_pattern = Regexp.new(@pattern)
19
20
  @documents.each do |doc|
20
21
  history_slugs = doc._slugs
21
22
  next if history_slugs.nil?
22
- existing_slugs.push(*history_slugs.find_all { |cur_slug| cur_slug =~ @pattern })
23
- last_entered_slug.push(*history_slugs.last) if history_slugs.last =~ @pattern
24
- existing_history_slugs.push(*history_slugs.first(history_slugs.length - 1).find_all { |cur_slug| cur_slug =~ @pattern })
23
+ existing_slugs.push(*history_slugs.find_all { |cur_slug| cur_slug =~ regexp_pattern })
24
+ 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).find_all { |cur_slug| cur_slug =~ regexp_pattern })
25
26
  end
26
27
  end
27
28
 
@@ -85,13 +86,8 @@ module Mongoid
85
86
 
86
87
  @_slug = @_slug[0...slug_max_length] if slug_max_length
87
88
 
88
- # Regular expression that matches slug, slug-1, ... slug-n
89
- # If slug_name field was indexed, MongoDB will utilize that
90
- # index to match /^.../ pattern.
91
- pattern = /^#{Regexp.escape(@_slug)}(?:-(\d+))?$/
92
-
93
89
  where_hash = {}
94
- where_hash[:_slugs.all] = [pattern]
90
+ where_hash[:_slugs.all] = [regex_for_slug]
95
91
  where_hash[:_id.ne] = model._id
96
92
 
97
93
  if (scope = slug_scope) && reflect_on_association(scope).nil?
@@ -100,11 +96,11 @@ module Mongoid
100
96
  where_hash[scope] = model.try(:read_attribute, scope)
101
97
  end
102
98
 
103
- if slug_by_model_type == true
99
+ if slug_by_model_type
104
100
  where_hash[:_type] = model.try(:read_attribute, :_type)
105
101
  end
106
102
 
107
- @state = SlugState.new @_slug, uniqueness_scope.unscoped.where(where_hash), pattern
103
+ @state = SlugState.new @_slug, uniqueness_scope.unscoped.where(where_hash), escaped_pattern
108
104
 
109
105
  # do not allow a slug that can be interpreted as the current document id
110
106
  @state.include_slug unless model.class.look_like_slugs?([@_slug])
@@ -122,6 +118,22 @@ module Mongoid
122
118
  end
123
119
  end
124
120
 
121
+ def escaped_pattern
122
+ "^#{Regexp.escape(@_slug)}(?:-(\\d+))?$"
123
+ end
124
+
125
+ # Regular expression that matches slug, slug-1, ... slug-n
126
+ # If slug_name field was indexed, MongoDB will utilize that
127
+ # index to match /^.../ pattern.
128
+ # Use Regexp::Raw to avoid the multiline option when querying the server.
129
+ def regex_for_slug
130
+ if embedded? || Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
131
+ Regexp.new(escaped_pattern)
132
+ else
133
+ Regexp::Raw.new(escaped_pattern)
134
+ end
135
+ end
136
+
125
137
  def uniqueness_scope
126
138
  if slug_scope && (metadata = reflect_on_association(slug_scope))
127
139
 
@@ -1,5 +1,5 @@
1
1
  module Mongoid #:nodoc:
2
2
  module Slug
3
- VERSION = '5.3.0'.freeze
3
+ VERSION = '5.3.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-slug
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Saebjoernsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-11 00:00:00.000000000 Z
11
+ date: 2017-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.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
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongoid-compatibility
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: stringex
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec-its
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: awesome_print
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: uuid
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: Mongoid URL slug or permalink generator
@@ -200,17 +200,17 @@ require_paths:
200
200
  - lib
201
201
  required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
- - - ">="
203
+ - - '>='
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - ">="
208
+ - - '>='
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project: mongoid-slug
213
- rubygems_version: 2.5.1
213
+ rubygems_version: 2.4.6
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: Mongoid URL slugs
@@ -250,3 +250,4 @@ test_files:
250
250
  - spec/shared/indexes.rb
251
251
  - spec/spec_helper.rb
252
252
  - spec/tasks/mongoid_slug_rake_spec.rb
253
+ has_rdoc: