Code Monkey home page Code Monkey logo

easy-record's Introduction

Header Ricardo's GitHub stats Top Langs

Technologies

  • ๐Ÿ’Ž Ruby
  • ๐Ÿš€ JavaScript (React.js and Vue.js)
  • ๐Ÿ˜ PHP
  • ๐Ÿณ Docker
Learning
  • ๐Ÿฆ€ Rust
  • ๐Ÿน Go

easy-record's People

Contributors

nandhae avatar ricvillagrana avatar sathia27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

easy-record's Issues

Option to assign the model as relationship

Right now we have this way to associate two records:

Assuming that list is a List instance.

Item.new(name: 'Item name', list_id: list.id)

But this way is cleaner and better (UPDATE TO THIS):

Item.new(name: 'Item name', list: list)

Also, would be nice to have this kind of assignments:

list.tasks.append(task)
task.list = list

model field validation will fail on nil assignement

class Person < EasyRecord
  field :name, String
end

person = Person.new(name: 'John')

# If we want to "clear" the name assigning `nil`, we will ge this error:
# RuntimeError: name cannot receive type `NilClass` because it is defined as `String`
person.name = nil

person.name should be able to get a nil assignment.

Validation in models

Validations are always needed. Currently, datatype is validated but I think it's also great having custom validations.

Example:

class Person < EasyRecord
  field name, String

  # The lambda funciton should return a boolean.
  validate :name, -> (name) { name.size < 50 }
end

has_many and belongs_to autodetect class

Current:

class List < EasyRecord
  field :name, String

  belongs_to :user, { class_name: 'User' }, 'user_id'
  has_many :tasks, class_name: 'Task'
end

New behaviour:

class List < EasyRecord
  field :name, String

  belongs_to :user # it will take class_name `User` and the key `user_id`
  has_many :tasks # it will pluralize and take the `Task` class_name.
end

support for save to json

We need to save our records in json structures.
The files should be places on storage/json/{model_name}.json

Add pluck method and ids method

  1. Is needed for 1:N relationships have a ids method to get an array of ids.
  2. Is needed to have a method pluck which take an attribute from the model lists and return an array of the attribute values.
  • Add ids method.
  • Add pluck method.

Examples

Person.ids # => ['8652b710-cb9f-0137-1165-2cbc32ad1b49', '8652b710-cb9f-0137-1165-2cbc32ad1b50']
Person.pluck :name # => ['John', 'Mike', 'Robin', 'Hannah']

Tests

Is needed to have test for this library.
Please use Minitest.

Change a method name

Currently I have a method called has_many_simple, but I think that has_many_directly is a better name.

The method is in the associations.rb file.

Feel free to suggest another name if you think is better.

Automatically add belongs_to attribute name to instance variables.

Currently, is needed to have the list_id in the attr_accessor, but would be nice if we can avoid this and only passing the name in the belongs_to.

class List < EasyRecord
  attr_accessor :name

  has_many :tasks, class_name: 'Task'
end

class Task < EasyRecord
  attr_accessor :name, :done, :list_id

  belongs_to :list, { class_name: 'List' }, :list_id
end

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.