Class: Apipie::ErrorDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/error_description.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code_or_options, desc = nil, options = {}) ⇒ ErrorDescription

Returns a new instance of ErrorDescription.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apipie/error_description.rb', line 11

def initialize(code_or_options, desc = nil, options = {})
  if code_or_options.is_a? Hash
    code_or_options.symbolize_keys!
    @code = code_or_options[:code]
    @metadata = code_or_options[:meta]
    @description = code_or_options[:desc] || code_or_options[:description]
  else
    @code =
      if code_or_options.is_a? Symbol
        begin
          Rack::Utils.status_code(code_or_options)
        rescue ArgumentError
          nil
        end
      else
        code_or_options
      end

    raise UnknownCode, code_or_options unless @code

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/apipie/error_description.rb', line 4

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/apipie/error_description.rb', line 4

def description
  @description
end

#metadataObject (readonly)

Returns the value of attribute metadata.



4
5
6
# File 'lib/apipie/error_description.rb', line 4

def 
  @metadata
end

Class Method Details

.from_dsl_data(args) ⇒ Object



6
7
8
9
# File 'lib/apipie/error_description.rb', line 6

def self.from_dsl_data(args)
  code_or_options, desc, options = args
  Apipie::ErrorDescription.new(code_or_options, desc, options)
end

Instance Method Details

#to_json(lang) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/apipie/error_description.rb', line 36

def to_json(lang)
  {
    :code => code,
    :description => Apipie.app.translate(description, lang),
    :metadata => 
  }
end