Class: SwaggerYard::Property
- Inherits:
-
Object
- Object
- SwaggerYard::Property
- Includes:
- Example
- Defined in:
- lib/swagger_yard/property.rb
Overview
Holds the name and type for a single model property
Constant Summary collapse
- NAME_OPTIONS_REGEXP =
/[\(\)]/
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, types, description, options) ⇒ Property
constructor
A new instance of Property.
- #required? ⇒ Boolean
Methods included from Example
Constructor Details
#initialize(name, types, description, options) ⇒ Property
59 60 61 62 63 64 |
# File 'lib/swagger_yard/property.rb', line 59 def initialize(name, types, description, ) @name, @description = name, description @required = .include?('required') @nullable = .include?('nullable') @type = Type.from_type_list(types) end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/swagger_yard/property.rb', line 8 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/swagger_yard/property.rb', line 7 def name @name end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
7 8 9 |
# File 'lib/swagger_yard/property.rb', line 7 def nullable @nullable end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
7 8 9 |
# File 'lib/swagger_yard/property.rb', line 7 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/swagger_yard/property.rb', line 7 def type @type end |
Class Method Details
.from_method(yard_method) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/swagger_yard/property.rb', line 22 def self.from_method(yard_method) return nil unless yard_method.explicit || yard_method.parameters.empty? = (yard_method. ||[]).dup prop_tag = .detect { |t| t.tag_name == 'property' } return nil unless prop_tag .reject { |t| t.tag_name == 'property' } from_tag(prop_tag).tap do |prop| ex = .detect { |t| t.tag_name == 'example' } prop.example = ex.text.empty? ? ex.name : ex.text if ex prop.description = yard_method.docstring unless prop.description end end |
.from_tag(tag) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/swagger_yard/property.rb', line 35 def self.from_tag(tag) tag = SwaggerYard.requires_type(tag) return nil unless tag name = tag_name(tag) return nil unless name text = tag.text if ( = (tag.name || '')) =~ NAME_OPTIONS_REGEXP _, = .split(NAME_OPTIONS_REGEXP) elsif tag.name && tag.object.is_a?(YARD::CodeObjects::MethodObject) if text text = tag.name + ' ' + text else text = tag.name end end = .to_s.split(',').map(&:strip) new(name, tag.types, text, ) end |
.tag_name(tag) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/swagger_yard/property.rb', line 12 def self.tag_name(tag) if tag.object.is_a?(YARD::CodeObjects::MethodObject) tag.object.name.to_s else tag = SwaggerYard.requires_name(tag) return nil unless tag tag.name.split(NAME_OPTIONS_REGEXP).first end end |
Instance Method Details
#required? ⇒ Boolean
66 67 68 |
# File 'lib/swagger_yard/property.rb', line 66 def required? @required end |