klriutsa / ruson Goto Github PK
View Code? Open in Web Editor NEWA Ruby serialization/deserialization library to convert Ruby Objects into JSON and back
License: MIT License
A Ruby serialization/deserialization library to convert Ruby Objects into JSON and back
License: MIT License
I have an expiredAt
attribute in the JSON file which is a timestamp (value: 1575608400.0
) but ruson doesn't convert it when I defined my model as the following:
class Vehicle < Ruson::Base
field :name
field :price
field :expired_at, name: 'expiredAt', class: Time
end
vehicle = Vehicle.new(name: 'Black Sims', price: 17.43, "expiredAt" => 1575608400.0)
vehicle.expired_at # => 1575608400-01-01 00:00:00.000000000 +0000
While it should be:
vehicle = Vehicle.new(name: 'Black Sims', price: 17.43, "expiredAt" => 1575608400.0)
vehicle.expired_at # => Fri, 06 Dec 2019 05:00:00.000000000 +0000
As of now, there's noway to get all the records:
class User < Ruson::Base
field :name
end
User.all
produces:
NoMethodError (undefined method `all' for User:Class)
I actually have to implement the find_by
method allowing me to search a model by name like so:
vehicle = Vehicle.find_by(name: 'Jean Bart')
Support enum status like moshi.
https://github.com/square/moshi#built-in-type-adapters
class Article < Ruson::Base
field :title
enum status: { :draft, :published }
end
{
"title":"Title",
"status":"draft"
}
article = Article.new(json_file)
article.status.draft? #=> true
Have you plan to add search and persistence methods to ruson?
My use case is fetching JSON from an API, and I'd like to save the created models using ruson, but also to update (find + save or find + create).
I'm looking for a methods find
, first_or_create
, and save
/save!
.
I'm expecting to give a folder where to save the JSON files to ruson, and when I'm saving a new model instance, to have a JSON file created in the given folder, using a sub folder with the model's class name, and object id as filename maybe?
Given a JSON that has a expiredAt
attributes, when I define my model as the following:
class Vehicle < Ruson::Base
field :expired_at, name: 'expiredAt', class: Time
end
And I try to create a new Vehicle
:
data = fetch_vehicle_data
vehicle = Vehicle.new(data) # data is like {"expiredAt" => 1575608400.0}
vehicle.expired_at # => nil
As of now, on rubygems.org and on this github repo, the description says:
A Ruby serialization/deserialization library to convert Ruby Objects into JSON and back
While the gem allow to do it, it does much more so I strongly think a new description should be made.
I suggestion I could make :
Ruson is an ODM (Object Document Mapper) Framework to JSON files, written in Ruby.
Hi @klriutsa,
Can you please release a new version of this gem after having merged the remaining PR?
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.