Sha256: 30775dc3d96843f9ed1ad90da5e901a48436e257a474f6b57208c66718cc11ae

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

require 'ice_cube'

module ScheduleAttributes
  class Serializer

    # Only load YAML serializations that are present, not empty strings
    # An invalid value can raise an error that gets caught by ActiveRecord
    # and results in the original string getting passed through. This allows
    # it to be saved back unchanged if necessary.
    #
    def self.load(yaml)
      IceCube::Schedule.from_yaml(yaml) if yaml.present?
    end

    # This should normally receive a Schedule object.
    # In some unknown circumstance that I can't reproduce, it would save an
    # already-dumped serialized YAML Schedule string into a YAML string
    # wrapper, effectively double-bagging the YAML. I only assume it receives a
    # String when loading a bad YAML value from the database, which then
    # propagates and re-re-serializes itself into YAML on every save.
    #
    def self.dump(schedule)
      case schedule
      when IceCube::Schedule then schedule.to_yaml
      when String            then schedule
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dgp-schedule_attributes-0.5.3 lib/schedule_attributes/serializer.rb
dgp-schedule_attributes-0.5.2 lib/schedule_attributes/serializer.rb
dgp-schedule_attributes-0.5.1 lib/schedule_attributes/serializer.rb
dgp-schedule_attributes-0.5.0 lib/schedule_attributes/serializer.rb
dgp-schedule_attributes-0.4.0 lib/schedule_attributes/serializer.rb
schedule_attributes-0.3.0 lib/schedule_attributes/serializer.rb