0.0
No commit activity in last 3 years
No release in over 3 years
Include EzlySerialize in any object you wish to serialize. EzlySerialize provides a serialize and a deserialize instance method and can be configured to use any serializer that implements an interface similar to JSON (specifically dump and load methods)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.16
>= 0
~> 10.0
~> 3.0
 Project Readme

EzlySerialize

EzlySerialize is a very simple gem that allows serialization of objects. It works out of the box with Marshal, JSON and MessagePack, but can be extended to work with any ser/deserializer that implements the methods dump and load in a similar way as JSON.

Installation

Add this line to your application's Gemfile:

gem 'ezly_serialize'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ezly_serialize

Usage

Let's assume that you have an object Person that looks like this

class Person
  attr_reader :name
  
  def initialize(name)
    @name = name
  end
end

In order to use EzlySerialize, you only need to include the module in the class and configure EzlySerialize to use the serializer of your preference.

class Person
  include EzlySerialize

  attr_reader :name

  def initialize(name)
    @name = name
  end
end

EzlySerialize::Configuration.serializer(JSON)

That's it! You can now easily serialize your object like that:

me = Person.new('Jason')
serialized = me.serialize # => {"name": "Jason"}

If you want to hydrate an object from a serialized value, you can use the deserialize method:

me = Person.new(nil)
me.deserialize(serialized)
puts me.name # => "Jason"

Note: EzlySerialize is not opinionated about deserialization and I've chosen to let the user instantiate the object and just hydrate it from a serialized object instead of engaging into metaprogramming and setting rules and conventions.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ezly_serialize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the EzlySerialize project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.