Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scheming

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scheming

  • 0.7.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Scheming

Ergonomically define and work with data in Ruby

Installation

gem 'scheming'

Usage

Simple Schema

Definition:

LineItem = Scheming.object do
  attribute :id, Union(Integer, String)
  attribute :name, String
  attribute :taxable, :bool
  attribute :price, Float

  tag(:optional)
  attribute :desc, Nullable(String)

  tag(:optional)
  attribute :item_type, Enum('entertainment', 'staple')
end

Point = Scheming.generic do |(type)|
  Object(x: type, y: type)
end

Receipt = Scheming.object do
  attribute :line_items, Array(LineItem)
  attribute :total, Float
  attribute :location, Point[Float]
end

Example:

Scheming::Schema.json(Receipt)
# =>
{
  type: 'object',
  additionalProperties: false,
  required: %w[line_items total location],
  properties: {
    line_items: {
      type: 'array',
      items: {
        type: 'object',
        additionalProperties: false,
        required: %w[id name taxable price],
        properties: {
          id: {
            oneOf: [
              { type: 'integer' },
              { type: 'string' }
            ]
          },
          name: { type: 'string' },
          taxable: { type: 'boolean' },
          desc: {
            oneOf: [
              { type: 'string' },
              { type: 'null' }
            ]
          },
          price: { type: 'number' },
          item_type: {
            type: 'string',
            enum: %w[entertainment staple]
          }
        }
      }
    },
    total: { type: 'number' },
    location: {
      type: 'object',
      additionalProperties: false,
      required: %w[x y],
      properties: {
        x: { type: 'number' },
        y: { type: 'number' }
      }
    }
  }
}

Development

Getting Started

To get going the following commands are helpful:

git clone https://github.com/benfalk/scheming.git
./scheming/setup
cd scheming
bundle exec rake

Installing Locally

To install this gem onto your local machine:

bundle exec rake install

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/benfalk/scheming.

License

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

FAQs

Package last updated on 10 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc