Class: Meta::RouteDSL::RouteBuilder

Inherits:
Object
  • Object
show all
Includes:
MetaBuilder::Delegator
Defined in:
lib/meta/route_dsl/route_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, method = :all, parent_path: '', &block) ⇒ RouteBuilder

这里的 path 局部的路径,也就是由 route 宏命令定义的路径



18
19
20
21
22
23
24
25
26
27
# File 'lib/meta/route_dsl/route_builder.rb', line 18

def initialize(path, method = :all, parent_path: '',&block)
  route_full_path = Utils::Path.join(parent_path, path)

  @path = path || ''
  @method = method || :all
  @action_builder = nil
  @meta_builder = MetaBuilder.new(route_full_path: route_full_path, route_method: method)

  instance_exec &block if block_given?
end

Instance Method Details

#action(&block) ⇒ Object



46
47
48
# File 'lib/meta/route_dsl/route_builder.rb', line 46

def action(&block)
  @action_builder = ActionBuilder.new(&block)
end

#build(meta_options: {}, callbacks: {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/meta/route_dsl/route_builder.rb', line 29

def build(meta_options: {}, callbacks: {})
  meta_options = Utils::RouteDSLBuilders.merge_meta_options(meta_options, @meta_builder.build)
  callbacks = Utils::RouteDSLBuilders.merge_callbacks(callbacks, [{ lifecycle: :before, proc: @action_builder&.build }])
  action = AroundActionBuilder.build_from_callbacks(callbacks: callbacks)

  Route.new(
    path: @path,
    method: @method,
    meta: meta_options,
    action: action
  )
end

#chainObject



42
43
44
# File 'lib/meta/route_dsl/route_builder.rb', line 42

def chain
  @action_builder || @action_builder = ChainBuilder.new
end