Skip to content

Add property type casting #4

@nesquena

Description

@nesquena

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"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions