Sha256: 1f0c77517bb15321fa700f740851e727bccfdf2c27ffb1d2dedd20578bb7ebc9
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
# Encore Encore is a framework built on top of ActiveRecord to manage entities. ## Installation Add this line to your application's Gemfile: ```ruby gem 'encore' ``` And then execute: ```bash $ bundle ``` Or install it yourself as: ```bash $ gem install encore ``` ## Usage ```ruby # app/entities/user_entity.rb class UserEntity include Encore::Entity expose :name expose :email expose :created_at, readonly: true expose :updated_at, readonly: true end # app/controllers/users_controller.rb class UsersController < ApplicationController # POST /users def create @user = UserEntity.new @user.assign_attributes(params[:user], context: :create) if @user.save render json: @user, status: 201 else render json: { errors: @user.errors }, status: 422 end end # PUT /users/:id def update @user = UserEntity.new User.find(params[:id]) @user.assign_attributes(params[:user], context: :update) if @user.save render json: @user else render json: { errors: @user.errors }, status: 422 end end # PATCH /users/:id def partial_update @user = UserEntity.find User.find(params[:id]) @user.assign_attributes(params[:user], context: :partial_update) if @user.save render json: @user else render json: { errors: @user.errors }, status: 422 end end end ```
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
encore-0.0.2 | README.md |