Class: Meta::Route
- Inherits:
-
Object
- Object
- Meta::Route
- Defined in:
- lib/meta/application/route.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #execute(execution, remaining_path) ⇒ Object
- #generate_operation_doc(schemas) ⇒ Object
-
#initialize(path: '', method: :all, meta: {}, action: nil) ⇒ Route
constructor
path 是局部 path,不包含由父级定义的前缀.
- #match?(execution, remaining_path) ⇒ Boolean
Constructor Details
#initialize(path: '', method: :all, meta: {}, action: nil) ⇒ Route
path 是局部 path,不包含由父级定义的前缀
14 15 16 17 18 19 |
# File 'lib/meta/application/route.rb', line 14 def initialize(path: '', method: :all, meta: {}, action: nil) @path = Utils::Path.normalize_path(path) @method = method @meta = Metadata.new() @action = action end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
11 12 13 |
# File 'lib/meta/application/route.rb', line 11 def action @action end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
11 12 13 |
# File 'lib/meta/application/route.rb', line 11 def @meta end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'lib/meta/application/route.rb', line 11 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/meta/application/route.rb', line 11 def path @path end |
Instance Method Details
#execute(execution, remaining_path) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/meta/application/route.rb', line 21 def execute(execution, remaining_path) path_matching.merge_path_params(remaining_path, execution.request) execution. = @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 |
#generate_operation_doc(schemas) ⇒ Object
41 42 43 44 |
# File 'lib/meta/application/route.rb', line 41 def generate_operation_doc(schemas) # 不再自动添加 $post 等 scope .generate_operation_doc(schemas, scope: []) end |
#match?(execution, remaining_path) ⇒ Boolean
31 32 33 34 35 36 37 38 39 |
# File 'lib/meta/application/route.rb', line 31 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 |