Module: JsonapiSwaggerHelpers::Readable

Included in:
IndexAction, ShowAction
Defined in:
lib/jsonapi_swagger_helpers/readable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 3

def self.included(klass)
  klass.class_eval do
    attr_reader :node,
      :controller,
      :resource,
      :description,
      :tags
  end
end

Instance Method Details

#all_tagsObject



49
50
51
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 49

def all_tags
  tags + payload_tags
end

#default_descriptionObject



21
22
23
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 21

def default_description
  "#{action_name.capitalize} Action"
end

#each_associationObject



70
71
72
73
74
75
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 70

def each_association
  resource_map = util.all_resources(resource, include_directive)
  resource_map.each_pair do |association_name, association_resource|
    yield association_name, association_resource
  end
end

#each_statObject



61
62
63
64
65
66
67
68
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 61

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_descriptionObject



45
46
47
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 45

def full_description
  "#{description}<br /><br />#{util.sideload_label(include_directive)}"
end

#generateObject



81
82
83
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 81

def generate
  raise 'override me'
end

#has_extra_fields?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 41

def has_extra_fields?
  resource.config[:extra_fields].keys.length > 1
end

#has_sideloads?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 37

def has_sideloads?
  include_directive.keys.length > 0
end

#include_directiveObject



33
34
35
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 33

def include_directive
  util.include_directive_for(controller, action_name)
end

#initialize(node, controller, description: nil, tags: []) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 13

def initialize(node, controller, description: nil, tags: [])
  @node = node
  @controller = controller
  @resource = controller._jsonapi_compliable
  @description = description || default_description
  @tags = tags
end

#jsonapi_typeObject



77
78
79
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 77

def jsonapi_type
  resource.config[:type]
end

#operation_idObject



25
26
27
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 25

def operation_id
  "#{controller.name.gsub('::', '-')}-#{action_name}"
end

#payload_tagsObject



53
54
55
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 53

def payload_tags
  util.payload_tags_for(resource, include_directive.to_hash)
end

#utilObject



29
30
31
# File 'lib/jsonapi_swagger_helpers/readable.rb', line 29

def util
  JsonapiSwaggerHelpers::Util
end