Class: SwaggerYard::Type
- Inherits:
-
Object
- Object
- SwaggerYard::Type
- Defined in:
- lib/swagger_yard/type.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
(also: #array?)
readonly
Returns the value of attribute array.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, array = false) ⇒ Type
constructor
A new instance of Type.
- #model_name ⇒ Object
-
#ref? ⇒ Boolean
TODO: have this look at resource listing?.
- #to_h ⇒ Object
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
#array ⇒ Object (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 |
#name ⇒ Object (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_name ⇒ Object
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?
15 16 17 |
# File 'lib/swagger_yard/type.rb', line 15 def ref? /[[:upper:]]/.match(name) end |
#to_h ⇒ Object
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 |