Giter VIP home page Giter VIP logo

vimo's Introduction

Vimo

Rails engine that allow to your users create and customize their own virtual models.

Warning

This engine is in a very early stage and the DSL and APIs could change, if you are interested on use it you can email me: [email protected].

Installation

Add this line to your application's Gemfile:

gem 'vimo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vimo

Usage

Expose the manage API

Add mount Vimo::Engine => "/vimo" in config/routers.rb to expose an restfull API to manage the virtual models and their contents.

CRUD of entities, where :entity is the id or system_name of the entity.

GET    /vimo/entities
POST   /vimo/entities
GET    /vimo/entities/:entity
PATCH  /vimo/entities/:entity
PUT    /vimo/entities/:entity
DELETE /vimo/entities/:entity

Entity attributes:

{
  "name": "posts",          # required
  "system_name": "posts",   # unique per owner
  "field_attributes": {
    "id": 42,               # just for update
    "name": "title",        # required
    "kind": "string",       # required, options: string, integer, float, boolean, date or datetime
    "required": true,       # options: true or false
    "_destroy": false,      # just for update, mark to destroy the field, options: true or false
  }
}

Create an entity curl example:

curl localhost:3000/vimo/entities -X POST -H 'Content-Type: application/json' -d '{"entity": {"name": "comments", "fields_attributes": [{"name": "title", "kind": "string", "required": true}]}}'

CRUD for your virtual models:

GET    /vimo/entities/:entity/items
POST   /vimo/entities/:entity/items
GET    /vimo/entities/:entity/items/:id
PATCH  /vimo/entities/:entity/items/:id
PUT    /vimo/entities/:entity/items/:id
DELETE /vimo/entities/:entity/items/:id

Create an item curl example:

curl localhost:3000/vimo/entities/comments/items -X POST -H 'Content-Type: application/json' -d '{"item" : {"title": "a title"}}'

Short path version

GET    /vimo/resources/:entity
POST   /vimo/resources/:entity
GET    /vimo/resources/:entity/:id
PATCH  /vimo/resources/:entity/:id
PUT    /vimo/resources/:entity/:id
DELETE /vimo/resources/:entity/:id

API authentication

Vimo allow you to authenticate and set ownership to your models.

Vimo.configure do |config|

  # The name of the before filter we'll call to authenticate the current user.
  # Defaults to :login_required
  config.authentication_method = :authenticate!

  # The name of the controller method we'll call to return the owner for
  # the virtual models.
  config.owner_method = :current_account
end

Setting a owner scope the uniquenes constraints.

The owner should respond to vimo_entities

class Account < ApplicationRecord
  vimo_owner
end

Expand your models

Having a model like Post that belongs to an Account you can allow to your users expand it.

class Post < ApplicationRecord
  belongs_to :account

  vimo_expand owner: :account
end

Now can manage the virtual attributes of the model Post with the identifier _expand_posts.

License

The gem is available as open source under the terms of the MIT License.

vimo's People

Contributors

ceritium avatar dependabot[bot] avatar depfu[bot] avatar

Watchers

 avatar

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.