rails_slugs 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,22 +39,25 @@ module RailsSlugs
39
39
  options = self.class.slug
40
40
  case options
41
41
  when Symbol
42
- value = send(options).parameterize
42
+ value = send(options)
43
43
  when Array
44
- value = options.each.map{|p|send(p)}.join(' ').parameterize
44
+ value = options.each.map{|p|send(p)}.join(' ')
45
45
  when Proc
46
- value = options.call(self).parameterize
46
+ value = options.call(self)
47
47
  end
48
- previous_value = previous_slug?(value)
49
- if previous_value.present?
50
- index = Regexp.new(value + '-(\d+)$').match(previous_value)
51
- if index.present?
52
- value << "-#{index[1].to_i + 1}"
53
- else
54
- value << '-1'
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 = '#{::I18n.locale.to_s}'"
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 => ::I18n.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
- ::I18n.locale = locale
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 = '#{::I18n.locale.to_s}'"
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
- ::I18n.available_locales.each do |locale|
136
+ I18n.available_locales.each do |locale|
134
137
  change_locale locale
135
138
  assign_slug
136
139
  end
@@ -1,5 +1,5 @@
1
1
  module RailsSlugs
2
2
 
3
- VERSION = '1.0.7'
3
+ VERSION = '1.0.8'
4
4
 
5
5
  end