vidibus-permalink 1.1.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/app/models/permalink.rb +25 -10
- data/lib/vidibus/permalink/mongoid.rb +14 -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: 51f420dad962971000b45f721fc1179b27e5736dce2b2b8bfa2ca5d058789cea
|
4
|
+
data.tar.gz: bdd0f56bb07da5d649b2b9b68e5545f18b9bcfcef7fcdf0ad442e564d0e0436c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a0ef6ac2e4225da6aa42abfbc8883999b5194b7e87bfd6e1b1576e4a3a0af70c655fcaa0028e78a342a28a041e7e991fb2bb68fc33eff84a9cb788b3a50826f
|
7
|
+
data.tar.gz: 76f55494e22bf48e18ed6f6107b414c3049b638c0e939fd5c6c11b77407d7aadd2d7d1a91f7273d8a4773447eaefb7d2aff745c76433ef88c3ae1b59b512effb
|
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,14 +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
|
-
|
71
|
-
|
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
|
72
82
|
end
|
73
83
|
|
74
84
|
def for_scope(scope)
|
@@ -83,9 +93,10 @@ class Permalink
|
|
83
93
|
|
84
94
|
# Sanitizes string: Remove stopwords and format as permalink.
|
85
95
|
# See Vidibus::CoreExtensions::String for details.
|
86
|
-
def sanitize(string)
|
96
|
+
def sanitize(string, keep_stopwords = false)
|
87
97
|
return if string.blank?
|
88
|
-
remove_stopwords(string)
|
98
|
+
string = remove_stopwords(string) unless keep_stopwords
|
99
|
+
string.permalink
|
89
100
|
end
|
90
101
|
|
91
102
|
def scope_list(scope)
|
@@ -147,7 +158,11 @@ class Permalink
|
|
147
158
|
# Sets _current to false on all permalinks of the assigned linkable.
|
148
159
|
def unset_other_current
|
149
160
|
return unless linkable
|
150
|
-
conditions = {
|
161
|
+
conditions = {
|
162
|
+
linkable_id: linkable.id,
|
163
|
+
linkable_type: linkable.class.to_s,
|
164
|
+
_id: {'$ne' => id}
|
165
|
+
}
|
151
166
|
conditions[:scope] = Permalink.scope_list(scope) if scope.present?
|
152
167
|
Permalink.where(conditions).each do |obj|
|
153
168
|
obj.set(_current: false)
|
@@ -157,7 +172,7 @@ class Permalink
|
|
157
172
|
# Sets the lastly updated permalink of the assigned linkable as current one.
|
158
173
|
def set_last_current
|
159
174
|
last = Permalink
|
160
|
-
.where(linkable_id: linkable.id)
|
175
|
+
.where(linkable_id: linkable.id, linkable_type: linkable.class.to_s)
|
161
176
|
.order_by(:updated_at.desc)
|
162
177
|
.limit(1)
|
163
178
|
.first
|
@@ -40,6 +40,18 @@ module Vidibus
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
# Ensure that a current permalink object exists for this record.
|
44
|
+
def ensure_permalink_object
|
45
|
+
if permalink_repository
|
46
|
+
permalink_object || begin
|
47
|
+
obj = permalink_object_by_value(permalink)
|
48
|
+
obj.sanitize_value!
|
49
|
+
obj.current!
|
50
|
+
obj.save
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
43
55
|
# Returns the defined permalink repository object.
|
44
56
|
def permalink_repository
|
45
57
|
@permalink_repository ||= begin
|
@@ -102,7 +114,7 @@ module Vidibus
|
|
102
114
|
end
|
103
115
|
|
104
116
|
# Initializes a new permalink object and sets permalink attribute.
|
105
|
-
def set_permalink
|
117
|
+
def set_permalink(force = false)
|
106
118
|
begin
|
107
119
|
attribute_names = self.class.permalink_attributes
|
108
120
|
rescue NoMethodError
|
@@ -115,7 +127,7 @@ module Vidibus
|
|
115
127
|
changed ||= send("#{name}_changed?")
|
116
128
|
values << send(name)
|
117
129
|
end
|
118
|
-
return unless permalink.blank? || changed
|
130
|
+
return unless permalink.blank? || changed || force
|
119
131
|
value = values.join(' ')
|
120
132
|
if permalink_repository
|
121
133
|
@permalink_object = permalink_object_by_value(value)
|
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.5.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-10-14 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
|