Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property type casting #4

Open
nesquena opened this issue Feb 1, 2012 · 1 comment
Open

Add property type casting #4

nesquena opened this issue Feb 1, 2012 · 1 comment
Assignees

Comments

@nesquena
Copy link
Collaborator

nesquena commented Feb 1, 2012

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"
@ghost ghost assigned nicotaing Feb 1, 2012
@nesquena
Copy link
Collaborator Author

nesquena commented Feb 9, 2012

Seems to be working here: https://github.com/Nico-Taing/yaml_record/commits/virtus_redux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants