Skip to content

Instantly share code, notes, and snippets.

@bricker
Created June 21, 2012 21:43
Show Gist options
  • Save bricker/2968717 to your computer and use it in GitHub Desktop.
Save bricker/2968717 to your computer and use it in GitHub Desktop.
Simple PyYAML constructor for handling Ruby Flash Hash
# Simple PyYAML constructor for handling Ruby Flash Hash
# Not perfect or graceful - just takes the Ruby Flash object
# and the Set object inside of it, and nullifies them.
# This could be expanded to handled different tags.
# If you wanted to maintain the Ruby objects across requests,
# or use convert a Ruby object to a Python object, you'll
# need something a little more complex, but this should get
# you started.
import yaml
def nullify_ruby_objects(loader, node):
# Below is an example of how you could map the keys/values
# However, with the FlashHash specifically, it won't work
# because it creases an alias when FlashNow exists.
# value = loader.construct_mapping(node)
# All that really matters is that we just return None (nil)
return None
yaml.add_constructor(u'!ruby/object:ActionDispatch::Flash::FlashHash', nullify_ruby_objects)
yaml.add_constructor(u'!ruby/object:ActionDispatch::Flash::FlashNow', nullify_ruby_objects)
yaml.add_constructor(u'!ruby/object:Set', nullify_ruby_objects)
yaml.load(session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment