mceachen/druthers — pull request #2 by JKillian (2014-01-04 01:05:55+00:00)
Title: Handle custom serialization

I wanted settings that are 'Integer' values to return an 'Integer' as opposed to a 'String', so I wrote a custom serializer as seen below:

class IntChecker
def self.load(string)
begin
Integer(string, 10)
rescue
string
end
end

def self.dump(val)
val.to_s
end
end

serialize :value, IntChecker

However, there was a small problem - say I had a setting called `food_num`. And it gets assigned to a string: `Settings.food_num = '20'`. The cache now holds the value `'20'` as a `String`, but if the cache gets cleared, we'll start getting the `Integer` version `20` back, as the `load` method of the serializer class will convert it to an `Integer`.

So this change fixes that problem and makes sure the cache returns values consistent with what is expected.