Rails的新架构:Trailblazer

jopen 10年前

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