Class: ApipieDSL::ExceptionDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie_dsl/exception_description.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_or_options, desc = nil, options = {}) ⇒ ExceptionDescription

Returns a new instance of ExceptionDescription.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/apipie_dsl/exception_description.rb', line 12

def initialize(error_or_options, desc = nil, options = {})
  if error_or_options.is_a?(Hash)
    error_or_options = error_or_options.transform_keys(&:to_sym)
    @error = error_or_options[:error]
    @metadata = error_or_options[:meta]
    @description = error_or_options[:desc] || error_or_options[:description]
  else
    @error = if error_or_options.is_a?(Symbol)
               Rack::Utils::SYMBOL_TO_STATUS_CODE[error_or_options]
             else
               error_or_options
             end
    raise ArgumentError, error_or_options unless @error

    @metadata = options[:meta]
    @description = desc
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/apipie_dsl/exception_description.rb', line 5

def description
  @description
end

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'lib/apipie_dsl/exception_description.rb', line 5

def error
  @error
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/apipie_dsl/exception_description.rb', line 5

def 
  @metadata
end

Class Method Details

.from_dsl_data(args) ⇒ Object



7
8
9
10
# File 'lib/apipie_dsl/exception_description.rb', line 7

def self.from_dsl_data(args)
  error_or_options, desc, options = args
  ApipieDSL::ExceptionDescription.new(error_or_options, desc, options)
end

Instance Method Details

#docsObject



31
32
33
34
35
36
37
# File 'lib/apipie_dsl/exception_description.rb', line 31

def docs
  {
    error: error,
    description: ApipieDSL.markup_to_html(description),
    metadata: 
  }
end