Module: RESTFramework::Mixins::BaseControllerMixin::ClassMethods
- Defined in:
- lib/rest_framework/mixins/base_controller_mixin.rb
Instance Method Summary collapse
-
#get_title ⇒ Object
By default, this is the name of the controller class, titleized and with any custom inflection acronyms applied.
-
#label_for(s) ⇒ Object
Get a label from a field/column name, titleized and inflected.
- #openapi_document(request, route_group_name, routes) ⇒ Object
-
#openapi_paths(routes, tag) ⇒ Object
:nocov:.
-
#rrf_finalize ⇒ Object
Define any behavior to execute at the end of controller definition.
Instance Method Details
#get_title ⇒ Object
By default, this is the name of the controller class, titleized and with any custom inflection acronyms applied.
47 48 49 50 51 52 |
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 47 def get_title return self.title || RESTFramework::Utils.inflect( self.name.demodulize.chomp("Controller").titleize(keep_id_suffix: true), self.inflect_acronyms, ) end |
#label_for(s) ⇒ Object
Get a label from a field/column name, titleized and inflected.
55 56 57 58 59 60 |
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 55 def label_for(s) return RESTFramework::Utils.inflect( s.to_s.titleize(keep_id_suffix: true), self.inflect_acronyms, ) end |
#openapi_document(request, route_group_name, routes) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 134 def openapi_document(request, route_group_name, routes) server = request.base_url + request.original_fullpath.gsub(/\?.*/, "") return { openapi: "3.1.1", info: { title: self.get_title, description: self.description, version: self.version.to_s, }.compact, servers: [{url: server}], paths: self.openapi_paths(routes, route_group_name), tags: [{name: route_group_name, description: self.description}.compact], }.compact end |
#openapi_paths(routes, tag) ⇒ Object
:nocov:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 74 def openapi_paths(routes, tag) response_content_types = [ "text/html", self.serialize_to_json ? "application/json" : nil, self.serialize_to_xml ? "application/xml" : nil, ].compact request_content_types = [ "application/json", "application/xml", "application/x-www-form-urlencoded", "multipart/form-data", ] return routes.group_by { |r| r[:concat_path] }.map { |concat_path, routes| [ concat_path.gsub(/:([0-9A-Za-z_-]+)/, "{\\1}"), routes.map { |route| = route[:route].defaults[:metadata] || {} summary = [:label].presence || self.label_for(route[:action]) description = [:description].presence = .except(:label, :description).presence [ route[:verb].downcase, { tags: [tag], summary: summary, description: description, responses: { 200 => { content: response_content_types.map { |ct| [ct, {}] }.to_h, description: "", }, }, requestBody: route[:verb].in?(["GET", "DELETE", "OPTIONS", "TRACE"]) ? nil : { content: request_content_types.map { |ct| [ct, {}] }.to_h, }, "x-rrf-metadata": , }.compact, ] }.to_h.merge( { parameters: routes.first[:route].required_parts.map { |p| { name: p, in: "path", required: true, schema: {type: "integer"}, } }, }, ), ] }.to_h end |
#rrf_finalize ⇒ Object
Define any behavior to execute at the end of controller definition. :nocov:
64 65 66 67 68 69 70 71 |
# File 'lib/rest_framework/mixins/base_controller_mixin.rb', line 64 def rrf_finalize if RESTFramework.config.freeze_config self::RRF_BASE_CONFIG.keys.each { |k| v = self.send(k) v.freeze if v.is_a?(Hash) || v.is_a?(Array) } end end |