class Swaggard::Swagger::Type

Constants

BASIC_TYPES

Attributes

name[R]

Public Class Methods

new(types) click to toggle source
# File lib/swaggard/swagger/type.rb, line 21
def initialize(types)
  parse(types)
end

Public Instance Methods

to_doc() click to toggle source
# File lib/swaggard/swagger/type.rb, line 25
def to_doc
  if @is_array
    { 'type' => 'array', 'items' => type_tag_and_name }
  else
    type_tag_and_name
  end
end

Private Instance Methods

basic_type?() click to toggle source
# File lib/swaggard/swagger/type.rb, line 43
def basic_type?
  BASIC_TYPES.has_key?(@name.downcase)
end
custom_type?() click to toggle source
# File lib/swaggard/swagger/type.rb, line 47
def custom_type?
  Swaggard.configuration.custom_types.has_key?(@name)
end
parse(types) click to toggle source
# File lib/swaggard/swagger/type.rb, line 35
def parse(types)
  parts = types.first.split(/[<>]/)

  @name = parts.last
  @is_array = parts.grep(/array/i).any?
end
type_tag_and_name() click to toggle source
# File lib/swaggard/swagger/type.rb, line 51
def type_tag_and_name
  if basic_type?
    BASIC_TYPES[@name.downcase].dup
  elsif custom_type?
    Swaggard.configuration.custom_types[@name].dup
  else
    { '$ref' => "#/definitions/#{name}" }
  end
end