Class: SwaggerYard::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/swagger_yard/type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, array = false) ⇒ Type

Returns a new instance of Type.



10
11
12
# File 'lib/swagger_yard/type.rb', line 10

def initialize(name, array=false)
  @name, @array = name, array
end

Instance Attribute Details

#arrayObject (readonly) Also known as: array?

Returns the value of attribute array.



8
9
10
# File 'lib/swagger_yard/type.rb', line 8

def array
  @array
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/swagger_yard/type.rb', line 8

def name
  @name
end

Class Method Details

.from_type_list(types) ⇒ Object



3
4
5
6
# File 'lib/swagger_yard/type.rb', line 3

def self.from_type_list(types)
  parts = types.first.split(/[<>]/)
  new(parts.last, parts.grep(/array/i).any?)
end

Instance Method Details

#model_nameObject



19
20
21
# File 'lib/swagger_yard/type.rb', line 19

def model_name
  ref? ? name : nil
end

#ref?Boolean

TODO: have this look at resource listing?

Returns:

  • (Boolean)


15
16
17
# File 'lib/swagger_yard/type.rb', line 15

def ref?
  /[[:upper:]]/.match(name)
end

#to_hObject



25
26
27
28
29
30
31
32
# File 'lib/swagger_yard/type.rb', line 25

def to_h
  type_tag = ref? ? "$ref" : "type"
  if array?
    {"type"=>"array", "items"=> { type_tag => name }}
  else
    {"type"=>name}
  end
end