Sha256: feef6b1b7fb2062a7ec392c80255e6906d8288693c7f1049bb2f5fd648984783
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 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) meta.generate_operation_doc(schemas, scope: ["$#{method}"]) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
meta-api-0.1.1 | lib//meta/application/route.rb |
meta-api-0.1.0 | lib//meta/application/route.rb |