Project

lector

0.0
No commit activity in last 3 years
No release in over 3 years
lector parses Ruby data into Ruby data structures.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

lector reads Ruby data from strings or files without necessarily evaluating either.

Oh yeah, and the build status? We have one of those: Build Status

Usage

Reading Strings

> require 'lector'
 => true
> Lector::read_s("{x: 11, :pants? => false}")
 => {:x=>11, :pants?=>false} 

Read-Eval

# read-eval is off by default:
> Lector::read_s("{three: #='1+2'}")
RuntimeError: Evaluation isn't allowed if :read_eval is false

# but when you turn it on...
> Lector::read_s("{three: #='1+2'}", :read_eval => true)
 => {:three=>3} 

Please see the tests for more usage examples.

Rationale

Ruby's literal support for hashes, arrays, keywords, numbers, and strings makes Ruby data slightly more expressive than JSON and arguably as expressive as YAML.

Ruby could be a decent format for representing things like markup or configuration data. This library allows you to digest Ruby data strings and files without having to worry if arbitrary code will execute.

Thanks

This library started as a fork of Michael Fogus and Alex Redington's clj.rb, a library for parsing Clojure data from Ruby. A big thanks to them for getting this party started.