rails_slugs 1.0.7 → 1.0.8
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.
- data/lib/rails_slugs/active_record/base.rb +19 -16
- data/lib/rails_slugs/version.rb +1 -1
- data/test/dummy/log/test.log +1379 -0
- data/test/rails_slugs_test.rb +1 -1
- data/test/records_test.rb +11 -5
- metadata +2 -2
@@ -39,22 +39,25 @@ module RailsSlugs
|
|
39
39
|
options = self.class.slug
|
40
40
|
case options
|
41
41
|
when Symbol
|
42
|
-
value = send(options)
|
42
|
+
value = send(options)
|
43
43
|
when Array
|
44
|
-
value = options.each.map{|p|send(p)}.join(' ')
|
44
|
+
value = options.each.map{|p|send(p)}.join(' ')
|
45
45
|
when Proc
|
46
|
-
value = options.call(self)
|
46
|
+
value = options.call(self)
|
47
47
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
if value.present?
|
49
|
+
value = value.parameterize
|
50
|
+
previous_value = previous_slug?(value)
|
51
|
+
if previous_value.present?
|
52
|
+
index = Regexp.new(value + '-(\d+)$').match(previous_value)
|
53
|
+
if index.present?
|
54
|
+
value << "-#{index[1].to_i + 1}"
|
55
|
+
else
|
56
|
+
value << '-1'
|
57
|
+
end
|
55
58
|
end
|
59
|
+
self.slug = value
|
56
60
|
end
|
57
|
-
self.slug = value
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
@@ -97,13 +100,13 @@ module RailsSlugs
|
|
97
100
|
joins(
|
98
101
|
"INNER JOIN #{t.table_name} t ON t.#{t.foreign_key} = #{table_name}.#{t.active_record_primary_key}"
|
99
102
|
).where(
|
100
|
-
"t.slug = '#{id}' AND t.locale = '#{
|
103
|
+
"t.slug = '#{id}' AND t.locale = '#{I18n.locale.to_s}'"
|
101
104
|
).readonly(false).first
|
102
105
|
end
|
103
106
|
|
104
107
|
def exists_by_slug(id)
|
105
108
|
t = reflect_on_association(:translations)
|
106
|
-
joins(:translations).exists?(t.table_name.to_sym => {:slug => id, :locale =>
|
109
|
+
joins(:translations).exists?(t.table_name.to_sym => {:slug => id, :locale => I18n.locale})
|
107
110
|
end
|
108
111
|
|
109
112
|
end
|
@@ -112,7 +115,7 @@ module RailsSlugs
|
|
112
115
|
protected
|
113
116
|
|
114
117
|
def change_locale(locale)
|
115
|
-
|
118
|
+
I18n.locale = locale
|
116
119
|
with_locale locale
|
117
120
|
end
|
118
121
|
|
@@ -121,7 +124,7 @@ module RailsSlugs
|
|
121
124
|
r = self.class.joins(
|
122
125
|
"INNER JOIN #{t.table_name} t ON t.#{t.foreign_key} = #{self.class.table_name}.#{t.active_record_primary_key}"
|
123
126
|
).where(
|
124
|
-
(new_record? ? '' : "#{self.class.table_name}.id != #{id} AND ") + "(t.slug = '#{slug}' OR t.slug LIKE '#{slug}-_') AND t.locale = '#{
|
127
|
+
(new_record? ? '' : "#{self.class.table_name}.id != #{id} AND ") + "(t.slug = '#{slug}' OR t.slug LIKE '#{slug}-_') AND t.locale = '#{I18n.locale.to_s}'"
|
125
128
|
).order(
|
126
129
|
't.slug DESC'
|
127
130
|
).first
|
@@ -130,7 +133,7 @@ module RailsSlugs
|
|
130
133
|
|
131
134
|
def generate_slugs
|
132
135
|
locale = current_locale
|
133
|
-
|
136
|
+
I18n.available_locales.each do |locale|
|
134
137
|
change_locale locale
|
135
138
|
assign_slug
|
136
139
|
end
|
data/lib/rails_slugs/version.rb
CHANGED