Project

blumquist

0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
What the summary said.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Blumquist Circle CI Coverage Status Gem Version

Given a JSON schema and some data, Blumquist will give you an immutable object that has getters defined for all properties from the JSON schema. Works well with schemas using JSON pointers as well as for properties that are themselves objects or arrays.

Usage

  1. Give it a schema
  2. Give it some data
  3. Get an object with getters

(Sorry, no profit step.)

1. Give it a schema

schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city":   { "type": "string" },
        "state":  { "type": "string" }
      },
      "required": ["street", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "name": { "type": "string" },
    "current_address": { "$ref": "#/definitions/address" },
    "old_addresses": { "type": "array", "items": { "$ref": "#/definitions/address"   } }
  }
}

2. Give it some data

data = {
  "name": "Moviepilot, Inc.",
  "current_address": {
    "street_address": "Friedrichstr. 58",
    "city": "Berlin",
    "state": "Berlin"
  },
  "old_addresses": [
    {
      "street_address": "Blücherstr. 22",
      "city": "Berlin",
      "state": "Berlin"
    },
    {
      "street_address": "Mehringdamm 33",
      "city": "Berlin",
      "state": "Berlin"
    }
  ]
}

3. And you get...

... an object with getters for all properties defined in the schema

> b = Blumquist.new(schema: schema, data: data)
=> #<Blumquist:0x0....>
> b.name
=> "Moviepilot, Inc."
> b.old_addresses.first.street
=> "Blücherstr. 22"

Validation

By default, Blumquist will validate the data. If you don't want that to happen, do as follows:

> b = Blumquist.new(schema: schema, data: data, validate: false)
=> ...

Installation

Add this line to your application's Gemfile:

gem 'blumquist'

And then execute:

$ bundle

Or install it yourself as:

$ gem install blumquist

Contributing

Bug reports and pull requests are welcome on GitHub in the issues section. 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.