A Ruby implementation for Rison - Compact Data in URIs.
Add this line to your application's Gemfile:
gem 'rison-rb'And then execute:
$ bundle
Or install it yourself as:
$ gem install rison-rb
This is a Ruby implementation for Rison that represents compact data in URIs. This module provides a parsing and dumping API like JSON module:
require "rison"
Rison.dump({ a: 1, b: true , c: ['foo', 'bar'] }) # => (a:1,b:!t,c:!(foo,bar))
Rison.parse('(a:1,b:!t,c:!(foo,bar))') # => { 'a' => 1, 'b' => true , 'c' => ['foo', 'bar'] }Parsing generates a hash key as a string, just like JSON module. But you can also switch keys to symbols with the symbolize_names option:
Rison.parse('(a:!(foo,bar,(b:1)))', symbolize_names: true) # => { a: ['foo', 'bar', { b: 1 }] }Similarly, O-Rison and A-Rison variations are supported:
# O-Rison
Rison.dump({ a: 1, b: 2 }, mode: :object) # => a:1,b:2
Rison.parse('a:1,b:2', mode: :object) # => { 'a' => 1, 'b' => 2 }
# A-Rison
Rison.dump(['foo', 'bar'], mode: :array) # => foo,bar
Rison.parse('foo,bar', mode: :array) # => ['foo', 'bar']The original syntax defines only alphanumeric and -_./~ as ASCII characters for idchar. But rison.js accepts other ASCII characters as idchar.
rison-rb conforms to the rison.js implementation. Therefore, it differs from the original syntax in the following points:
- It accepts ASCII characters other than
<space>'!:(),*@$and all non-ASCII characters as idchar. - Numbers starting with 0 are allowed.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/wata727/rison-rb. 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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the rison-rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.