Class: OasCore::Builders::ContentBuilder
- Inherits:
-
Object
- Object
- OasCore::Builders::ContentBuilder
- Defined in:
- lib/oas_core/builders/content_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(specification) ⇒ ContentBuilder
constructor
A new instance of ContentBuilder.
- #with_content_type(content_type) ⇒ Object
- #with_examples(examples) ⇒ Object
- #with_examples_from_tags(tags) ⇒ Object
- #with_schema(schema) ⇒ Object
Constructor Details
#initialize(specification) ⇒ ContentBuilder
Returns a new instance of ContentBuilder.
6 7 8 9 10 |
# File 'lib/oas_core/builders/content_builder.rb', line 6 def initialize(specification) @specification = specification @media_type = Spec::MediaType.new(specification) @content_type = 'application/json' end |
Instance Method Details
#build ⇒ Object
51 52 53 54 55 |
# File 'lib/oas_core/builders/content_builder.rb', line 51 def build { @content_type => @media_type } end |
#with_content_type(content_type) ⇒ Object
28 29 30 31 32 |
# File 'lib/oas_core/builders/content_builder.rb', line 28 def with_content_type(content_type) @content_type = content_type if content_type && !content_type.empty? self end |
#with_examples(examples) ⇒ Object
22 23 24 25 26 |
# File 'lib/oas_core/builders/content_builder.rb', line 22 def with_examples(examples) @media_type.examples = @specification.components.add_example(examples) self end |
#with_examples_from_tags(tags) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/oas_core/builders/content_builder.rb', line 34 def () @media_type.examples = @media_type.examples.merge(.each_with_object({}).with_index(1) do |(example, result), _index| key = example.text.downcase.gsub(' ', '_') if example.content.is_a? OasCore::Spec::Reference result[key] = example.content else value = { 'summary' => example.text, 'value' => example.content } result[key] = @specification.components.add_example(value) end end) self end |