Class: Brainstem::ApiDocs::Formatters::OpenApiSpecification::Version2::PresenterFormatter

Inherits:
AbstractFormatter
  • Object
show all
Includes:
Helper
Defined in:
lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#format_http_method, #format_sentence, #format_tag_name, #presenter_title, #type_and_format, #uncapitalize

Methods inherited from AbstractFormatter

call

Methods included from Concerns::Optional

#valid_options

Constructor Details

#initialize(presenter, options = {}) ⇒ PresenterFormatter

Returns a new instance of PresenterFormatter.



14
15
16
17
18
19
20
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 14

def initialize(presenter, options = {})
  self.presenter  = presenter
  self.definition = ActiveSupport::HashWithIndifferentAccess.new
  self.output     = ActiveSupport::HashWithIndifferentAccess.new

  super options
end

Instance Attribute Details

#definitionObject

Returns the value of attribute definition.



22
23
24
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 22

def definition
  @definition
end

#outputObject

Returns the value of attribute output.



22
23
24
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 22

def output
  @output
end

#presented_classObject

Returns the value of attribute presented_class.



22
23
24
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 22

def presented_class
  @presented_class
end

#presenterObject

Returns the value of attribute presenter.



22
23
24
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 22

def presenter
  @presenter
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/brainstem/api_docs/formatters/open_api_specification/version_2/presenter_formatter.rb', line 27

def call
  return {} if presenter.nodoc?

  format_title!
  format_description!
  format_type!
  format_fields!
  sort_properties!

  output.merge!(presenter.target_class => definition.reject {|_, v| v.blank?})
end