GithubHelp home page GithubHelp logo

yaml_record's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

yaml_record's Issues

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"

Add associations

We should add association support:

class Post < YamlRecord::Base
   belongs_to :episode
   # auto-adds `property :episode_id, Integer`
end

This adds a episode_id integer foreign key reference. You can then do stuff like:

p = Post.new
p.episode = Episode.find(5)
p.save
p.episode # => <Episode id=5>
p.episode_id # => 5

or:

p = Post.new
p.episode_id = 5
p.save
p.episode # => <Episode id=5>
p.episode_id # => 5

Also adds embeds_many support:

class Post < YamlRecord::Base
  embeds_many :users
  # adds property :user_ids, Array, Integer
end

and allows for:

p = Post.new
p.user_ids = "1,2,3"
p.save
p.users # => [<User 1>, <User 2>, <User 3>]

Add validations

Add validation support to yaml_record. Simplest will be to be able to define valid? and then have it run on update_attributes and save:

class Post < YamlRecord::Base
  def valid?
    errors add :title, "cannot be blank" if title.blank?
    errors.add :description, "cannot be blank" if self.description.blank?
  end
end

and then:

p = Post.new.save => false
p.errors # => { :title => ["cannot be blank"], :description => ["cannot be blank"] }

We can also add helpers as well:

class Post < YamlRecord::Base
  validates_presence_of :title
  validates_presence_of :description
end

which will automatically set:

p = Post.new.save => false
p.errors # => { :title => ["cannot be blank"], :description => ["cannot be blank"] }

Add array type for property

Once we have typecasting, we should support array as a type:

class Post < YamlRecord::Base
  property :names, Array 
  property :user_ids, Array[Integer]
end

and that should allow:

p = Post.new
p.names = ["Bob", "Jane"]
p.user_ids = [1,2,3,4,5]
p.save

to

---
names: ["Bob", "Jane"]
user_id: [1,2,3,4,5]

but also support lists in string form:

p = Post.new
p.names = "Bob, Jane"
p.user_ids = "1, 2, 3, 4, 5"
p.save
p.names   # => ["Bob", "Jane"]
p.user_ids # => [1,2,3,4,5]

Troubles on dependencies

Hello,

i tried to add yaml_record to a rails 4.1 project and i got that error:

yaml_record (>= 0) ruby depends on
activesupport (~> 2.3.11) ruby

My activesupport version is actually 4.1.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.