Class: ApiSchema::SerializerDefinition
- Inherits:
-
Object
- Object
- ApiSchema::SerializerDefinition
- Includes:
- Swagger::Blocks::ClassMethods
- Defined in:
- lib/api_schema/serializer_definition.rb
Defined Under Namespace
Classes: PriorReference
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #build_references ⇒ Object
-
#initialize(id, type, name = nil, parent_id = nil) ⇒ SerializerDefinition
constructor
A new instance of SerializerDefinition.
- #method_missing(type, *args, &block) ⇒ Object
- #reference(refernce_id, type: :object, desc: nil) ⇒ Object
- #required_fields ⇒ Object
Constructor Details
#initialize(id, type, name = nil, parent_id = nil) ⇒ SerializerDefinition
Returns a new instance of SerializerDefinition.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/api_schema/serializer_definition.rb', line 12 def initialize(id, type, name=nil, parent_id = nil) @id = id @type = type @name = name || id @parent = self.class.serializers[parent_id] @fields = parent&.fields || [] @prior_references = parent&.prior_references || [] @references = [] self.class.serializers[id] = self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/api_schema/serializer_definition.rb', line 10 def description @description end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
9 10 11 |
# File 'lib/api_schema/serializer_definition.rb', line 9 def fields @fields end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/api_schema/serializer_definition.rb', line 9 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/api_schema/serializer_definition.rb', line 10 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/api_schema/serializer_definition.rb', line 9 def parent @parent end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
9 10 11 |
# File 'lib/api_schema/serializer_definition.rb', line 9 def references @references end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/api_schema/serializer_definition.rb', line 10 def type @type end |
Class Method Details
.serializers ⇒ Object
23 24 25 |
# File 'lib/api_schema/serializer_definition.rb', line 23 def self.serializers @serializers end |
Instance Method Details
#build ⇒ Object
35 36 37 38 39 |
# File 'lib/api_schema/serializer_definition.rb', line 35 def build build_references sd = self swagger_schema(id) { schema_for(sd) } end |
#build_references ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/api_schema/serializer_definition.rb', line 41 def build_references @prior_references.each do |pr| reference = self.class.serializers[pr.id].clone reference.type = pr.type reference.description = pr.desc reference.name = reference.name.to_s.pluralize if reference.type == :array @references << reference end end |
#reference(refernce_id, type: :object, desc: nil) ⇒ Object
31 32 33 |
# File 'lib/api_schema/serializer_definition.rb', line 31 def reference(refernce_id, type: :object, desc: nil) @prior_references << PriorReference.new(refernce_id, type, desc) end |
#required_fields ⇒ Object
27 28 29 |
# File 'lib/api_schema/serializer_definition.rb', line 27 def required_fields fields.select { |f| f.required? }.map(&:name) + references.map(&:name) end |