Giter Site home page Giter Site logo

yaml-safe_load_stream2's Introduction

YAMLSafeLoadStream provided by yaml-safe_load_stream2

Gem Version Yard Docs

Before you begin...

The yaml-safe_load_stream2 project is a fork of kontena/k8s-client.

Unfortunately the company Kontena.io went bankcrupt at the end of the year 2019. They had created many wonderful Ruby projects which we are grateful.

The yaml-safe_load_stream2 library is a community effort to keep yaml-safe_load_stream maintained without any dependencies to the former Kontena.io organization. The library was renamed in order to publish it to Rubygems without conflicting with yaml-safe_load_stream.

Abstract

The Ruby standard library YAML/Psych module defines YAML.safe_load for safely loading YAML documents

There's also YAML.load_stream for loading multi-document streams.

The problem is, there's no YAML.safe_load_stream that would safely load a stream with multiple documents.

This gem adds a very bare bones implementation of that missing feature.

Usage

There is just one method: safe_load_stream(yaml_content, optional_filename_to_be_used_in_exception_messages)

When used with a block, it will yield each document separately:

YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n") do |document|
  puts document.inspect
end

# outputs:
# { 'hello' => 'world' }
# { 'hello' => 'universe' }

When used without a block, it will return an Array containing documents in the stream:

docs = YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")
puts docs.inspect

# outputs:
# [{ 'hello' => 'world' }, { 'hello' => 'universe' }]

Directly

require 'yaml/safe_load_stream'

YAMLSafeLoadStream.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

As a refinement

require 'yaml/safe_load_stream'
using YAMLSafeLoadStream

YAML.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

Requiring the core-ext

require 'yaml/safe_load_stream/core-ext'
YAML.safe_load_stream("---\nhello: world\n\n---\nhello: universe\n")

Installation

Add this line to your application's Gemfile:

gem 'yaml-safe_load_stream2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install yaml-safe_load_stream2

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tsutsu/yaml-safe_load_stream2

yaml-safe_load_stream2's People

Contributors

kke avatar tsutsu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.