Ruby设计哲学

来源:互联网 发布:java切面编程 编辑:程序博客网 时间:2024/05/21 11:36

Ruby设计哲学


  • Follow web standards and HTTP 遵循Web标准和HTTP
  • CoC (Convention over Configuration) 约定大于配置
  • MVC (Model-View-Controller)
  • DRY 不要重复造轮子(如:gems )
  • Software Engineering Patterns
  • Assets 静态资源
  • Restful API
  • Testing 测试
  • Deployment 部署
  • Automation 自动化(数据修改,移植)

Agile Development 敏捷开发

  • Philosophy
  • DRY
  • Ecosystem: Gems / Community

从本地开发到线上

  • Development Environments: Development / Test / Production / Staging(自定义模拟线上环境)
  • Test
  • Configurations 配置
  • Deployment 部署

Pages & Assets

  • Dynamic pages: Routes / Restful / Inheritance(继承)
  • Assets: Asset Pipeline / Minify / Combine / Webpack / babel etc.

Dynamic Pages

  • Routes 路由
    • HTTP GET/POST/PUT/DELETE
    • Custom routes
    • Easy to refactor
  • Filter 过滤器
    • before_filter
    • around_filter
    • after_filter
  • Cache 缓存
    • Page Cache
    • Fragment Cache
  • Response
    • HTML
    • JSON
    • XML
    • etc.

ActiveRecord

  • Powerful ORM
    User.find(2)    User.find_by(email: 'service@abc.com')    User.where(membership: 'gold').page(2)      .per_page(10).order("id desc").limit(10)    user.blogs
  • Triggers 回调
    • before_save
    • after_save
    • after_destroy
    • after_create
    • etc.

Assets

  • Javascript/CSS minify and combine
  • Assets URL
  • ETag
  • SASS
  • CoffeeScript

从开发到测试

  • Unit Test: rspec / minitest
  • Smoke Test / Continuous Integration: cucumber / selenium

脚本和自动化

  • rails c
  • rails g
  • rails s
  • etc.
  • rake task
    • rake routes
    • rake db:create
    • rake db:migrate
    • etc.

自定义rake任务

Libraries

  • gem
  • bundle
  • rails是很多gems的组合
  • 创建自己的gem
0 0
原创粉丝点击