Module: OpenAPIRest::Extension::ClassMethods
- Defined in:
- lib/openapi_rest/extension.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#openapi_path ⇒ Object
readonly
Returns the value of attribute openapi_path.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#openapi_path ⇒ Object (readonly)
Returns the value of attribute openapi_path.
11 12 13 |
# File 'lib/openapi_rest/extension.rb', line 11 def openapi_path @openapi_path end |
Class Method Details
.included(clazz) ⇒ Object
7 8 9 |
# File 'lib/openapi_rest/extension.rb', line 7 def self.included(clazz) clazz.send(:before_filter, :retrieve_openapi_path) end |
Instance Method Details
#render_rest(response) ⇒ Object
30 31 32 |
# File 'lib/openapi_rest/extension.rb', line 30 def render_rest(response) OpenAPIRest::RestRenderer.new(controller: self, response: response).render end |
#retrieve_openapi_path ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/openapi_rest/extension.rb', line 13 def retrieve_openapi_path all_routes = Rails.application.routes.routes path = request.path nspace = '' all_routes.each do |r| next unless r.defaults.fetch(:openapi, false) && Regexp.new(r.verb).match(request.method) match = Regexp.new(r.path.source).match(request.path) next unless match nspace = r.defaults.fetch(:namespace, '') match.captures.each_with_index { |c, i| path.gsub!(c, "{#{r.path.names[i]}}") unless c.nil? } end @openapi_path = { method: request.method.downcase, path: path, namespace: "#{nspace}_" } params.merge!(openapi_path: @openapi_path) end |