0.01
No commit activity in last 3 years
No release in over 3 years
Convert deeply nested Virtus or other objects that respond to attributes to hashes and arrays
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.8
~> 2.0
~> 10.0
~> 3.2
~> 0.9.2
 Project Readme

VirtusConvert

VirtusConvert allows you to convert a deeply nested tree of Virtus* or other objects that respond to attributes to nested tree of hashes and arrays

Installation

Add this line to your application's Gemfile:

gem 'virtus_convert'

And then execute:

$ bundle

Or install it yourself as:

$ gem install virtus_convert

Usage

jack = Person.new(name:'Jack', address:'123 Fake Street' )
order = Order.new(customer: jack, total:1_000_000)

VirtusConvert.new(order).to_hash #=> {customer:{name:'Jack', address:'123 Fake Street'}, total: 1000000}

Options

You can optionally pass in a options hash to make things more fancy like

reject_nils

Set reject nils to true tor reject nils

jack = Person.new(name: 'Jack', address: nil, items: [1,2,nil,3])
VirtusConvert.new(jack, reject_nils: true).to_hash #=> {name: 'Jack', items: [1,2,3] }

Look in the specs/ folder for more example use cases

Development

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

Contributing

  1. Fork it ( https://github.com/[my-github-username]/virtus_convert/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write Tests!
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request