Sha256: c68af7278b30a2bd5bba9c5a5c6495f51bd34b677e401a1304042f7579401df9
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
# frozen_string_literal: true require_relative 'execution' require_relative 'path_matching_mod' require_relative 'metadata' module Meta class Route include PathMatchingMod.new(path_method: :path, matching_mode: :full) attr_reader :path, :method, :meta, :action # path 是局部 path,不包含由父级定义的前缀 def initialize(path: '', method: :all, meta: {}, action: nil) @path = Utils::Path.normalize_path(path) @method = method @meta = Metadata.new(meta) @action = action end def execute(execution, remaining_path) path_matching.merge_path_params(remaining_path, execution.request) execution.route_meta = @meta # 解析参数的准备 action.execute(execution) if action @meta.set_response(execution) if @meta.responses rescue Execution::Abort execution.response.status = 200 if execution.response.status == 0 end def match?(execution, remaining_path) request = execution.request remaining_path = '' if remaining_path == '/' method = request.request_method return false unless path_matching.match?(remaining_path) return false unless @method == :all || @method.to_s.upcase == method return true end def generate_operation_doc(schemas) # 不再自动添加 $post 等 scope meta.generate_operation_doc(schemas, scope: []) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
meta-api-0.2.0 | lib//meta/application/route.rb |
meta-api-0.1.2 | lib//meta/application/route.rb |