Class: ScheduleAttributes::Serializer
- Inherits:
-
Object
- Object
- ScheduleAttributes::Serializer
- Defined in:
- lib/schedule_attributes/serializer.rb
Class Method Summary collapse
-
.dump(schedule) ⇒ Object
This should normally receive a Schedule object.
-
.load(yaml) ⇒ Object
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.
Class Method Details
.dump(schedule) ⇒ Object
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.
22 23 24 25 26 27 |
# File 'lib/schedule_attributes/serializer.rb', line 22 def self.dump(schedule) case schedule when IceCube::Schedule then schedule.to_yaml when String then schedule end end |
.load(yaml) ⇒ Object
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.
11 12 13 |
# File 'lib/schedule_attributes/serializer.rb', line 11 def self.load(yaml) IceCube::Schedule.from_yaml(yaml) if yaml.present? end |