lib/super_settings/setting.rb in super_settings-1.0.2 vs lib/super_settings/setting.rb in super_settings-2.0.0

- old
+ new

@@ -107,10 +107,11 @@ # Get all settings that have been updated since the specified time stamp. # # @param time [Time] # @return [Array<Setting>] def updated_since(time) + time = SuperSettings::Coerce.time(time) storage.with_connection do storage.updated_since(time).collect { |record| new(record) } end end @@ -217,10 +218,20 @@ params.each do |setting_params| setting_params = stringify_keys(setting_params) next if Coerce.blank?(setting_params["key"]) next if ["value_type", "value", "description", "deleted"].all? { |name| Coerce.blank?(setting_params[name]) } + key_was = setting_params["key_was"] + if key_was && !changed.include?(key_was) + old_setting = Setting.find_by_key(key_was) + if old_setting + old_setting.deleted = true + old_setting.changed_by = changed_by + changed[old_setting.key] = old_setting + end + end + key = setting_params["key"] setting = changed[key] || Setting.find_by_key(key) unless setting next if Coerce.present?(setting_params["delete"]) setting = Setting.new(key: setting_params["key"]) @@ -370,11 +381,11 @@ # Set the time when the setting was created. # # @param val [Time, DateTime] def created_at=(val) - val = Coerce.time(val) + val = TimePrecision.new(val).time will_change!(:created_at, val) unless created_at == val @record.created_at = val end # Get the time the setting was last updated. @@ -386,10 +397,10 @@ # Set the time when the setting was last updated. # # @param val [Time, DateTime] def updated_at=(val) - val = Coerce.time(val) + val = TimePrecision.new(val).time will_change!(:updated_at, val) unless updated_at == val @record.updated_at = val end # Return true if the setting has a string value type.