djanowski-permalink_fu 0.1.4 → 0.1.5
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/rails/tasks/permalink_fu.rake +30 -0
- metadata +2 -1
@@ -0,0 +1,30 @@
|
|
1
|
+
namespace :permalinks do
|
2
|
+
desc 'Re-builds permalinks for all models.'
|
3
|
+
task :rebuild => :environment do
|
4
|
+
models = if ENV['MODEL']
|
5
|
+
Array(ENV['MODEL'].constantize)
|
6
|
+
else
|
7
|
+
Dir[RAILS_ROOT + "/app/models/**/*.rb"].each { |f| require f }
|
8
|
+
ActiveRecord::Base.send(:subclasses)
|
9
|
+
end
|
10
|
+
|
11
|
+
models.each do |model|
|
12
|
+
next unless model.respond_to?(:permalink_field)
|
13
|
+
|
14
|
+
field = model.permalink_field
|
15
|
+
|
16
|
+
objects = nil
|
17
|
+
|
18
|
+
while objects.nil? || !objects.empty?
|
19
|
+
objects = model.find(:all, :conditions => {:permalink => nil}, :limit => 20)
|
20
|
+
|
21
|
+
objects.each do |o|
|
22
|
+
o.send(:create_unique_permalink)
|
23
|
+
value = o.send(model.permalink_field)
|
24
|
+
puts "#{model} #{o.id} => #{value.inspect}"
|
25
|
+
model.update_all("#{field} = '#{value}'", "id = #{o.id}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djanowski-permalink_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Janowski
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/permalink_fu/rake/tasks.rb
|
26
26
|
- lib/permalink_fu/spec/matchers.rb
|
27
27
|
- lib/permalink_fu.rb
|
28
|
+
- rails/tasks/permalink_fu.rake
|
28
29
|
- init.rb
|
29
30
|
- README.markdown
|
30
31
|
- MIT-LICENSE
|