Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wata727/rison-rb
A Ruby implementation for Rison
https://github.com/wata727/rison-rb
Last synced: 2 months ago
JSON representation
A Ruby implementation for Rison
- Host: GitHub
- URL: https://github.com/wata727/rison-rb
- Owner: wata727
- License: mit
- Created: 2019-10-27T08:14:38.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T09:54:59.000Z (about 5 years ago)
- Last Synced: 2024-10-12T23:15:07.380Z (3 months ago)
- Language: Ruby
- Size: 43 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# rison-rb
[![Build Status](https://github.com/wata727/rison-rb/workflows/build/badge.svg?branch=master)](https://github.com/wata727/rison-rb/actions)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE.txt)
[![Gem Version](https://badge.fury.io/rb/rison-rb.svg)](https://badge.fury.io/rb/rison-rb)A Ruby implementation for [Rison - Compact Data in URIs](https://rison.io).
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'rison-rb'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install rison-rb
## Usage
This is a Ruby implementation for Rison that represents compact data in URIs. This module provides a parsing and dumping API like JSON module:
```ruby
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'] }
```### Symbolize names
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:
```ruby
Rison.parse('(a:!(foo,bar,(b:1)))', symbolize_names: true) # => { a: ['foo', 'bar', { b: 1 }] }
```### O-Rison and A-Rison
Similarly, O-Rison and A-Rison variations are supported:
```ruby
# 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']
```### Differences from the original syntax
[The original syntax](https://rison.io) defines only alphanumeric and `-_./~` as ASCII characters for idchar. But [rison.js](https://github.com/Nanonid/rison) 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 `'!:(),*@$` and all non-ASCII characters as idchar.
- Numbers starting with 0 are allowed.## 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](https://rubygems.org).
## Contributing
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](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the rison-rb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wata727/rison-rb/blob/master/CODE_OF_CONDUCT.md).