ActiveModelSerializers::HashWrapper
Automatically create wrapper classes for Hashes so ActiveModelSerializers will serialize your hash!
Installation
Add this line to your application's Gemfile:
gem 'active_model_serializers-hash_wrapper'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_model_serializers-hash_wrapper
Usage
Let's say you have a hash, and you would like AMS to serialize it. You can create a wrapper class for your hash like so:
item_class = ActiveModelSerializers::HashWrapper.wrapper_class("Item")
wrapped_item = item_class.new(hash)
Or, for simplicity, you can do all this in one line:
wrapped_item = ActiveModelSerializers::HashWrapper.create("Item", hash)
Wrapper classes created by ActiveModelSerializers::HashWrapper
pass all AMS lint tests and can safely be used.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ptrln/active_model_serializers-hash_wrapper.