Project

emery

0.0
Low commit activity in last 3 years
No release in over a year
Type safety library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

Emery

Emery is a type safety library for Ruby. It provides a way to define types and serialize/deserialize them to/from JSON with type certainty and safety

Basic Usage Example

Here's basic example of Emery type checking:

require 'emery'

my_var = T.check(T.array(String), ["the string"])
# my_var is ["the string"]

my_var = T.check(T.array(String), "the string")
# Throws: Value '"the string"' type is String - Array is required

Here's type safe JSON serialization/deserialization:

require 'emery'

the_json = Jsoner.to_json(T.array(DateTime), [DateTime.new(2019, 11, 30, 17, 45, 55)])
# the_json is '["2019-11-30T17:45:55"]'

data = Jsoner.from_json(T.array(DateTime), '["2019-11-30T17:45:55+00:00"]')
# data is Array with the only one item which is corresponding DateTime