Module: JsonapiSwaggerHelpers::Readable
- Included in:
- IndexAction, ShowAction
- Defined in:
- lib/jsonapi_swagger_helpers/readable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #all_tags ⇒ Object
- #default_description ⇒ Object
- #each_association ⇒ Object
- #each_stat ⇒ Object
- #full_description ⇒ Object
- #generate ⇒ Object
- #generate_response_schema! ⇒ Object
- #has_extra_fields? ⇒ Boolean
- #has_sideloads? ⇒ Boolean
- #include_directive ⇒ Object
- #initialize(node, controller, description: nil, tags: [], singular: false) ⇒ Object
- #jsonapi_type ⇒ Object
- #operation_id ⇒ Object
- #payload_tags ⇒ Object
- #response_schema_id ⇒ Object
- #util ⇒ Object
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 5 def self.included(klass) klass.class_eval do attr_reader :node, :controller, :resource, :description, :tags, :singular end end |
Instance Method Details
#all_tags ⇒ Object
53 54 55 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 53 def + end |
#default_description ⇒ Object
25 26 27 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 25 def default_description "#{action_name.capitalize} Action" end |
#each_association ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 74 def each_association types = [jsonapi_type] resource_map = util.all_resources(resource, include_directive) resource_map.each_pair do |association_name, association_resource| resource_type = association_resource.config[:type] next if types.include?(resource_type) types << resource_type yield association_name, association_resource end end |
#each_stat ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 65 def each_stat resource.config[:stats].each_pair do |stat_name, opts| calculations = opts.calculations.keys - [:keys] calculations = calculations.join(', ') yield stat_name, calculations end end |
#full_description ⇒ Object
49 50 51 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 49 def full_description "#{description}<br /><br />#{util.sideload_label(include_directive)}" end |
#generate ⇒ Object
106 107 108 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 106 def generate raise 'override me' end |
#generate_response_schema! ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 93 def generate_response_schema! _self = self payloads = util.payloads_for(resource, include_directive.to_hash) JsonapiSwaggerHelpers.docs_controller.send(:swagger_schema, response_schema_id) do payloads.each do |p| property p.name do key :'$ref', p.name end end end end |
#has_extra_fields? ⇒ Boolean
45 46 47 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 45 def has_extra_fields? resource.config[:extra_fields].keys.length > 1 end |
#has_sideloads? ⇒ Boolean
41 42 43 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 41 def has_sideloads? include_directive.keys.length > 0 end |
#include_directive ⇒ Object
37 38 39 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 37 def include_directive util.include_directive_for(controller, action_name) end |
#initialize(node, controller, description: nil, tags: [], singular: false) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 16 def initialize(node, controller, description: nil, tags: [], singular: false) @node = node @controller = controller @resource = controller._jsonapi_compliable @description = description || default_description = @singular = singular end |
#jsonapi_type ⇒ Object
85 86 87 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 85 def jsonapi_type resource.config[:type] end |
#operation_id ⇒ Object
29 30 31 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 29 def operation_id "#{controller.name.gsub('::', '-')}-#{action_name}" end |
#payload_tags ⇒ Object
57 58 59 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 57 def util.(resource, include_directive.to_hash) end |
#response_schema_id ⇒ Object
89 90 91 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 89 def response_schema_id "#{operation_id}_#{action_name}_response" end |
#util ⇒ Object
33 34 35 |
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 33 def util JsonapiSwaggerHelpers::Util end |