Class: Spree::Preference
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Preference
- Defined in:
- app/models/spree/preference.rb
Class Method Summary collapse
-
.convert_old_value_types(preference) ⇒ Object
For the rc releases of 1.0, we stored the object class names, this converts to preferences definition types.
Instance Method Summary collapse
- #raw_value ⇒ Object
-
#value ⇒ Object
The type conversions here should match the ones in spree::preferences::preferrable#convert_preference_value.
Class Method Details
.convert_old_value_types(preference) ⇒ Object
For the rc releases of 1.0, we stored the object class names, this converts to preferences definition types. This code should eventually be removed. it is called during the load_preferences of the Preferences::Store
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/spree/preference.rb', line 36 def self.convert_old_value_types(preference) return unless [Symbol.to_s, Fixnum.to_s, Bignum.to_s, Float.to_s, TrueClass.to_s, FalseClass.to_s].include? preference.value_type case preference.value_type when Symbol.to_s preference.value_type = 'string' when Fixnum.to_s preference.value_type = 'integer' when Bignum.to_s preference.value_type = 'integer' preference.value = preference.value.to_f.to_i when Float.to_s preference.value_type = 'decimal' when TrueClass.to_s preference.value_type = 'boolean' preference.value = "true" when FalseClass.to_s preference.value_type = 'boolean' preference.value = "false" end preference.save end |
Instance Method Details
#raw_value ⇒ Object
29 30 31 |
# File 'app/models/spree/preference.rb', line 29 def raw_value self[:value] end |
#value ⇒ Object
The type conversions here should match the ones in spree::preferences::preferrable#convert_preference_value
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/spree/preference.rb', line 10 def value if self[:value_type].present? case self[:value_type].to_sym when :string, :text self[:value].to_s when :password self[:value].to_s when :decimal BigDecimal.new(self[:value].to_s).round(2, BigDecimal::ROUND_HALF_UP) when :integer self[:value].to_i when :boolean (self[:value].to_s =~ /^[t|1]/i) != nil end else self[:value] end end |