Module: SchemaGraphy::TagUtils
- Defined in:
- lib/schemagraphy/tag_utils.rb
Overview
A utility module for working with the custom tag data structure.
The structure is a hash with 'value' and '__tag__' keys.
Class Method Summary collapse
-
.detag(value) ⇒ Object
Extracts the original value from a tagged data structure.
-
.tag?(value, tag) ⇒ Boolean
Checks if a value has a specific tag.
-
.tag_of(value) ⇒ String?
Retrieves the tag from a tagged data structure.
Class Method Details
.detag(value) ⇒ Object
Extracts the original value from a tagged data structure.
11 12 13 |
# File 'lib/schemagraphy/tag_utils.rb', line 11 def self.detag value value.is_a?(Hash) && value.key?('value') ? value['value'] : value end |
.tag?(value, tag) ⇒ Boolean
Checks if a value has a specific tag.
28 29 30 |
# File 'lib/schemagraphy/tag_utils.rb', line 28 def self.tag? value, tag tag_of(value)&.to_s == tag.to_s end |
.tag_of(value) ⇒ String?
Retrieves the tag from a tagged data structure.
19 20 21 |
# File 'lib/schemagraphy/tag_utils.rb', line 19 def self.tag_of value value.is_a?(Hash) ? value['__tag__'] : nil end |