Class: SwaggerYard::Property
- Inherits:
-
Object
- Object
- SwaggerYard::Property
- Defined in:
- lib/swagger_yard/property.rb
Overview
Holds the name and type for a single model property
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, types, description, required) ⇒ Property
constructor
A new instance of Property.
- #model_name ⇒ Object
- #required? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(name, types, description, required) ⇒ Property
Returns a new instance of Property.
16 17 18 19 20 |
# File 'lib/swagger_yard/property.rb', line 16 def initialize(name, types, description, required) @name, @description, @required = name, description, required @type = Type.from_type_list(types) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/swagger_yard/property.rb', line 6 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/swagger_yard/property.rb', line 6 def name @name end |
Class Method Details
.from_tag(tag) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/swagger_yard/property.rb', line 8 def self.from_tag(tag) name, = tag.name.split(/[\(\)]/) required = .to_s.split(',').map(&:strip).include?('required') new(name, tag.types, tag.text, required) end |
Instance Method Details
#model_name ⇒ Object
26 27 28 |
# File 'lib/swagger_yard/property.rb', line 26 def model_name @type.model_name end |
#required? ⇒ Boolean
22 23 24 |
# File 'lib/swagger_yard/property.rb', line 22 def required? @required end |
#to_h ⇒ Object
30 31 32 33 34 |
# File 'lib/swagger_yard/property.rb', line 30 def to_h result = @type.to_h result["description"] = description if description result end |