Module: ElasticGraph::SchemaDefinition::Mixins::HasDocumentation
- Included in:
- SchemaElements::Argument, SchemaElements::EnumType, SchemaElements::EnumValue, SchemaElements::Field, SchemaElements::ScalarType, SchemaElements::TypeWithSubfields, SchemaElements::UnionType
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb
Overview
Supports GraphQL documentation.
Instance Attribute Summary collapse
-
#doc_comment ⇒ String?
Current documentation string for the schema element.
Instance Method Summary collapse
-
#append_to_documentation(comment) ⇒ void
Appends some additional documentation to the existing documentation string.
-
#derived_documentation(intro, outro = nil) ⇒ String
Generates a documentation string that is derived from the schema elements existing documentation.
-
#documentation(comment) ⇒ void
Sets the documentation of the schema element.
-
#formatted_documentation ⇒ String
Formats the documentation using GraphQL SDL syntax.
Instance Attribute Details
#doc_comment ⇒ String?
Returns current documentation string for the schema element.
17 18 19 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb', line 17 def doc_comment @doc_comment end |
Instance Method Details
#append_to_documentation(comment) ⇒ void
This method returns an undefined value.
Appends some additional documentation to the existing documentation string.
46 47 48 49 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb', line 46 def append_to_documentation(comment) new_documentation = doc_comment ? "#{doc_comment}\n\n#{comment}" : comment documentation(new_documentation) end |
#derived_documentation(intro, outro = nil) ⇒ String
Generates a documentation string that is derived from the schema elements existing documentation.
64 65 66 67 68 69 70 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb', line 64 def derived_documentation(intro, outro = nil) outro &&= "\n\n#{outro}." return "#{intro}.#{outro}" unless doc_comment quoted_doc = doc_comment.split("\n").map { |line| "> #{line}" }.join("\n") "#{intro}:\n\n#{quoted_doc}#{outro}" end |
#documentation(comment) ⇒ void
This method returns an undefined value.
Sets the documentation of the schema element.
38 39 40 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb', line 38 def documentation(comment) self.doc_comment = comment end |
#formatted_documentation ⇒ String
Formats the documentation using GraphQL SDL syntax.
54 55 56 57 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/mixins/has_documentation.rb', line 54 def formatted_documentation return nil unless (comment = doc_comment) %("""\n#{comment.chomp}\n"""\n) end |