seejohnrun/ice_cube — pull request #231 by wallace (2014-05-16 17:35:37+00:00)
Title: HashParser#schedule handles a nil value for @hash

In a Rails application I'm serializing an attribute, `schedule`, using the `Icecube::Schedule` class. When I'm unable to load any objects where the `schedule` has not been set, i.e. it has a `nil` value. This is due to the deserialization that occurs within `HashParser#to_schedule` method.

When Rails attempts to load an ActiveRecord object that has a serialized `IceCube::Schedule` class it calls `IceCube::Schedule.load`, https://github.com/wallace/ice_cube/blob/master/lib/ice_cube/schedule.rb#L386. The call chain eventually calls `HashParser#to_schedule`, https://github.com/wallace/ice_cube/blob/master/lib/ice_cube/schedule.rb#L343 with a nil value for @hash which results in a TypeError "can't dup NilClass" when `HashParser` attempts to normalize the keys.

This pull request ensures that `to_schedule` handles a `nil` value in the @hash by default to an empty hash when @hash is `nil`. I'd prefer to use `to_h` but that's not available in Ruby 1.9.3. :(