Sha256: 78c953157383ebad38244f814a15f30a8220b3914073530d3fa047144d1e7991

Contents?: true

Size: 709 Bytes

Versions: 7

Compression:

Stored size: 709 Bytes

Contents

module Spree
  class OldPrefs < ActiveRecord::Base
    set_table_name "spree_preferences"
    belongs_to  :owner, :polymorphic => true
    attr_accessor :owner_klass
  end

  class PreferenceRescue
    def self.try
      OldPrefs.where(:key => nil).each do |old_pref|
        next unless owner = (old_pref.owner rescue nil)
        unless old_pref.owner_type == "Spree::Activator" || old_pref.owner_type == "Spree::Configuration"
          old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
          old_pref.value_type = owner.preference_type(old_pref.name)
          puts "Migrating Preference: #{old_pref.key}"
          old_pref.save
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spree_core-1.0.7 lib/spree/core/preference_rescue.rb
spree_core-1.0.6 lib/spree/core/preference_rescue.rb
spree_core-1.0.4 lib/spree/core/preference_rescue.rb
spree_core-1.0.3 lib/spree/core/preference_rescue.rb
spree_core-1.0.2 lib/spree/core/preference_rescue.rb
spree_core-1.0.1 lib/spree/core/preference_rescue.rb
spree_core-1.0.0 lib/spree/core/preference_rescue.rb