| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

Rails的新架构:Trailblazer

Trailblazer是一个在Rails之上的一个轻微封装。它轻微地加强了封装,使代码结构更直观,并为您提供了一个面向对象的架构。
Trailblazer让你能够编写逻辑少的模型,扮演一个纯的数据对象,没有包含回调,嵌套属性,校验或域的逻辑。它消除了笨重的控制器。

A Concept-Driven OOP Framework

Trailblazer offers you a new, more intuitive file layout in Rails apps where you structure files by concepts.

app  ├── concepts  │   ├── comment  │   │   ├── cell.rb  │   │   ├── views  │   │   │   ├── show.haml  │   │   │   ├── list.haml  │   │   ├── assets  │   │   │   ├── comment.css.sass  │   │   ├── operation.rb  │   │   ├── twin.rb

Files, classes and views that logically belong to one concept are kept in one place. You are free to use additional namespaces within a concept. Trailblazer tries to keep it as simple as possible, though.

Architecture

Trailblazer extends the conventional MVC stack in Rails. Keep in mind that adding layers doesn't necessarily mean adding more code and complexity.

The opposite is the case: Controller, view and model become lean endpoints for HTTP, rendering and persistence. Redundant code gets eliminated by putting very little application code into the right layer.

Rails的新架构:Trailblazer

Routing

Trailblazer uses Rails routing to map URLs to controllers (we will add simplifications to routing soon).

Controllers

Controllers are lean endpoints for HTTP. They differentiate between request formats like HTML or JSON and immediately dispatch to an operation. Controllers do not contain any business logic.

Trailblazer provides four methods to present and invoke operations. But before that, you need to include the Controller module.

class CommentsController < ApplicationController        include Trailblazer::Operation::Controller 

项目主页:http://www.open-open.com/lib/view/home/1417239177706

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1417239177706.html
Ruby开发 Trailblazer