yaml_record
yaml_record copied to clipboard
Add property type casting
Old property declaration is:
class Post < YamlRecord::Base
# Declare your properties
properties :title, :body, :user_id
end
which leaves the properties as whatever types they are inside the YAML. But we should support type casting as well:
class Post < YamlRecord::Base
# Declare your properties
property :title, String
property :body, String
property :user_id, Integer
property :enabled, Boolean
property :created_at, DateTime
end
This should typecast for String
, Integer
, DateTime
, and Boolean
. This means that it will serialize and deserialize and properly cast types:
p = Post.new(:title => "Test", :user_id => "6", :enabled => "1", :created_at => "6/18/2012")
p.title # => "Test"
p.user_id # => 6
p.enabled # => true
p.created_at # => <Time ...>
and also properly write types out:
---
title: "Test"
user_id : 6
enabled : true
created_at: "2011-11-05T08:15:30Z"
Seems to be working here: https://github.com/Nico-Taing/yaml_record/commits/virtus_redux