Class: Meta::Utils::RouteDSLBuilders

Inherits:
Object
  • Object
show all
Defined in:
lib/meta/utils/route_dsl_builders.rb

Class Method Summary collapse

Class Method Details

.merge_callbacks(parent_callbacks, current_callbacks) ⇒ Object



22
23
24
25
26
27
# File 'lib/meta/utils/route_dsl_builders.rb', line 22

def merge_callbacks(parent_callbacks, current_callbacks)
  # 合并父级传递过来的 callbacks,将 before 和 around 放在前面,after 放在后面
  parent_before = parent_callbacks.filter { |cb| cb[:lifecycle] == :before || cb[:lifecycle] == :around }
  parent_after = parent_callbacks.filter { |cb| cb[:lifecycle] == :after }
  parent_before + current_callbacks + parent_after
end

.merge_meta_options(options1, options2) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/meta/utils/route_dsl_builders.rb', line 7

def merge_meta_options(options1, options2)
  final_options = (options1 || {}).merge(options2 || {})
  if options1[:parameters] && options2[:parameters]
    final_options[:parameters] = options1[:parameters].merge(options2[:parameters])
  end
  if options1[:request_body].is_a?(Meta::JsonSchema::ObjectSchema) && options2[:request_body].is_a?(Meta::JsonSchema::ObjectSchema)
    final_options[:request_body] = options1[:request_body].properties.merge(options2[:request_body].properties)
  end
  if options1[:responses] && options2[:responses]
    final_options[:responses] = options1[:responses].merge(options2[:responses])
  end
  final_options[:scope] = [options1[:scope] || [], options2[:scope] || []].flatten.uniq
  final_options
end