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

yaml_exporter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml_exporter

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

YamlExporter

YamlExporter is a Ruby gem that provides YAML serialization and deserialization functionality for ActiveRecord models, with JSON schema generation for validation.

Features

  • Serialize ActiveRecord models to YAML
  • Deserialize YAML back to ActiveRecord models
  • Generate JSON schemas for model validation
  • Support for nested associations (has_many and has_one)
  • Automatic type inference based on database column types

Installation

Add this line to your application's Gemfile:

gem 'yaml_exporter'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install yaml_exporter

Usage

Setting up your model

Include the YamlExporter module in your ActiveRecord model and define the YAML structure:


class Quiz < ApplicationRecord
  include YamlExporter

  yaml_structure do
    yaml_attribute :title, :quiz_type
    yaml_has_many :questions do
      yaml_attribute :text, :question_type, :feedback
      yaml_has_many :answers do
        yaml_attribute :text, :is_correct, :impact
      end
    end
  end
end

Serializing to YAML

To serialize a model instance to YAML:

quiz = Quiz.find(1)
yaml_string = quiz.yaml_export

Deserializing from YAML

To deserialize YAML back to a model instance:

quiz = Quiz.new
quiz.yaml_import(yaml_string)

Generating JSON Schema

To generate a JSON schema for validation:

schema = Quiz.yaml_schema

Configuration

The YamlExporter automatically infers types based on the database column types. JSON and JSONB columns are treated as objects in the generated schema.

Contributing

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

License

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

FAQs

Package last updated on 29 Aug 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