Rails源代码分析(33):ActionController::Routing(4) Builder

1 说明
  这个类用于根据path来创建Route对象

2 代码分析
  核心:
  1.       def build(path, options)
  2.         # Wrap the path with slashes
  3.         path = "/#{path}" unless path[0] == ?/
  4.         path = "#{path}/" unless path[-1] == ?/
  5.         path = "/#{options[:path_prefix].to_s.gsub(/^///,'')}#{path}" if options[:path_prefix]
  6.         segments = segments_for_route_path(path)
  7.         defaults, requirements, conditions = divide_route_options(segments, options)
  8.         requirements = assign_route_options(segments, defaults, requirements)
  9.         route = Route.new
  10.         route.segments = segments
  11.         route.requirements = requirements
  12.         route.conditions = conditions
  13.         if !route.significant_keys.include?(:action) && !route.requirements[:action]
  14.           route.requirements[:action] = "index"
  15.           route.significant_keys << :action
  16.         end
  17.         # Routes cannot use the current string interpolation method
  18.         # if there are user-supplied <tt>:requirements</tt> as the interpolation
  19.         # code won't raise RoutingErrors when generating
  20.         if options.key?(:requirements) || route.requirements.keys.to_set != Routing::ALLOWED_REQUIREMENTS_FOR_OPTIMISATION
  21.           route.optimise = false
  22.         end
  23.         if !route.significant_keys.include?(:controller)
  24.           raise Argum
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值