vidibus-permalink 1.1.1 → 1.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 +5 -5
- data/app/models/permalink.rb +26 -10
- data/lib/vidibus/permalink/mongoid.rb +2 -2
- data/lib/vidibus/permalink/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d118d572faff0ee081b71af77b77058c3a7226fcb9339467684fd9402ab1ba75
|
4
|
+
data.tar.gz: 06f9e27805f167fde0af86c410ea42905bffaf50235404dcafe6d4201bc33412
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6387c90b049d3f7985b35bc4ee7aa539a6919d839ad0f5e12742b156a35e70566b3e4ae60a295ab5876add428260f53356770c080bb0da6c78792744d637cacd
|
7
|
+
data.tar.gz: de8536cb2af02207d2b8145496a3deaa17819ae66e922cd3656166e5e5d841c044df6a8ce5f49b40deb2162479669ccee01e3a478b4d5f6d5afb1ecdedbf4227
|
data/app/models/permalink.rb
CHANGED
@@ -2,7 +2,7 @@ class Permalink
|
|
2
2
|
include Mongoid::Document
|
3
3
|
include Mongoid::Timestamps
|
4
4
|
|
5
|
-
belongs_to :linkable, polymorphic: true
|
5
|
+
belongs_to :linkable, polymorphic: true, autosave: false
|
6
6
|
|
7
7
|
field :value
|
8
8
|
field :scope, type: Array
|
@@ -47,7 +47,11 @@ class Permalink
|
|
47
47
|
if current?
|
48
48
|
self
|
49
49
|
else
|
50
|
-
Permalink.where(
|
50
|
+
Permalink.where({
|
51
|
+
linkable_id: linkable.id,
|
52
|
+
linkable_type: linkable.class.to_s,
|
53
|
+
_current: true
|
54
|
+
}).first
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
@@ -61,13 +65,20 @@ class Permalink
|
|
61
65
|
class << self
|
62
66
|
# Scope method for finding Permalinks for given object.
|
63
67
|
def for_linkable(object)
|
64
|
-
where(linkable_id: object.id)
|
68
|
+
where(linkable_id: object.id, linkable_type: object.class.to_s)
|
65
69
|
end
|
66
70
|
|
67
71
|
# Scope method for finding Permalinks for given value.
|
68
72
|
# The value will be sanitized.
|
69
|
-
def for_value(value)
|
70
|
-
|
73
|
+
def for_value(value, do_sanitize = true)
|
74
|
+
if do_sanitize
|
75
|
+
self.or([
|
76
|
+
{value: /^#{sanitize(value)}(-\d+)?$/},
|
77
|
+
{value: /^#{sanitize(value, true)}(-\d+)?$/}
|
78
|
+
])
|
79
|
+
else
|
80
|
+
where(value: /^#{value}(-\d+)?$/)
|
81
|
+
end
|
71
82
|
end
|
72
83
|
|
73
84
|
def for_scope(scope)
|
@@ -82,9 +93,10 @@ class Permalink
|
|
82
93
|
|
83
94
|
# Sanitizes string: Remove stopwords and format as permalink.
|
84
95
|
# See Vidibus::CoreExtensions::String for details.
|
85
|
-
def sanitize(string)
|
96
|
+
def sanitize(string, keep_stopwords = false)
|
86
97
|
return if string.blank?
|
87
|
-
remove_stopwords(string)
|
98
|
+
string = remove_stopwords(string) unless keep_stopwords
|
99
|
+
string.permalink
|
88
100
|
end
|
89
101
|
|
90
102
|
def scope_list(scope)
|
@@ -138,7 +150,7 @@ class Permalink
|
|
138
150
|
@existing ||= {}
|
139
151
|
@existing[string] ||= Permalink
|
140
152
|
.for_scope(scope)
|
141
|
-
.
|
153
|
+
.for_value(string, false)
|
142
154
|
.excludes(:_id => id)
|
143
155
|
.to_a
|
144
156
|
end
|
@@ -146,7 +158,11 @@ class Permalink
|
|
146
158
|
# Sets _current to false on all permalinks of the assigned linkable.
|
147
159
|
def unset_other_current
|
148
160
|
return unless linkable
|
149
|
-
conditions = {
|
161
|
+
conditions = {
|
162
|
+
linkable_id: linkable.id,
|
163
|
+
linkable_type: linkable.class.to_s,
|
164
|
+
_id: {'$ne' => id}
|
165
|
+
}
|
150
166
|
conditions[:scope] = Permalink.scope_list(scope) if scope.present?
|
151
167
|
Permalink.where(conditions).each do |obj|
|
152
168
|
obj.set(_current: false)
|
@@ -156,7 +172,7 @@ class Permalink
|
|
156
172
|
# Sets the lastly updated permalink of the assigned linkable as current one.
|
157
173
|
def set_last_current
|
158
174
|
last = Permalink
|
159
|
-
.where(linkable_id: linkable.id)
|
175
|
+
.where(linkable_id: linkable.id, linkable_type: linkable.class.to_s)
|
160
176
|
.order_by(:updated_at.desc)
|
161
177
|
.limit(1)
|
162
178
|
.first
|
@@ -112,8 +112,8 @@ module Vidibus
|
|
112
112
|
changed = false
|
113
113
|
values = []
|
114
114
|
attribute_names.each do |name|
|
115
|
-
changed ||=
|
116
|
-
values <<
|
115
|
+
changed ||= send("#{name}_changed?")
|
116
|
+
values << send(name)
|
117
117
|
end
|
118
118
|
return unless permalink.blank? || changed
|
119
119
|
value = values.join(' ')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-permalink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Pankratz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -184,8 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: 1.3.6
|
186
186
|
requirements: []
|
187
|
-
|
188
|
-
rubygems_version: 2.6.11
|
187
|
+
rubygems_version: 3.0.6
|
189
188
|
signing_key:
|
190
189
|
specification_version: 4
|
191
190
|
summary: Permalink handling
|