Sha256: dafbe2464b9be02293f90e43b038eeae0ab26ba4c9c30891518edc3971faa060

Contents?: true

Size: 872 Bytes

Versions: 6

Compression:

Stored size: 872 Bytes

Contents

require 'auto_html/task'

# Rake task for rebuilding cached in DB auto_html columns values
# Usage: rake auto_html:rebuild CLASS=[your model]
# Where [your model] is the name of model which contains auto_html_for columns

namespace :auto_html do
  desc "Rebuild auto_html columns"
  task :rebuild => :environment do

    klass  = AutoHtml::Task.obtain_class.constantize
    suffix = AutoHtmlFor.auto_html_for_options[:htmlized_attribute_suffix]
    column_names = klass.respond_to?(:column_names) ? klass.column_names : klass.fields.keys
    observed_attributes = column_names.select { |c| c=~/#{suffix}$/ }.map { |c| c.gsub(/#{suffix}$/, '')}

    i = 0
    klass.find_each do |item|
      observed_attributes.each do |field|
        item.send("#{field}=", item.send(field))
      end
      item.save
      i += 1
    end

    puts "Done! Processed #{i} items."
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
auto_html-whistlerbrk-2.0.0.pre lib/auto_html/rake_tasks.rb
auto_html-1.6.4 lib/auto_html/rake_tasks.rb
auto_html-1.6.3 lib/auto_html/rake_tasks.rb
auto_html-1.6.2 lib/auto_html/rake_tasks.rb
auto_html-1.6.1 lib/auto_html/rake_tasks.rb
auto_html-1.6.0 lib/auto_html/rake_tasks.rb