You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -298,6 +298,61 @@ The value of `@container` in a term definition can include `@id` or `@type`, in
298
298
}
299
299
}
300
300
301
+
### Transparent Nesting
302
+
Many JSON APIs separate properties from their entities using an intermediate object. For example, a set of possible labels may be grouped under a common property:
"main_label": "This is the main label for my resource",
316
+
"other_label": "This is the other label"
317
+
}
318
+
}
319
+
320
+
In this case, the `labels` property is semantically meaningless. Defining it as equivalent to `@nest` causes it to be ignored when expanding, making it equivalent to the following:
"main_label": "This is the main label for my resource",
333
+
"other_label": "This is the other label"
334
+
}
335
+
336
+
Similarly, properties may be marked with "@nest": "nest-term", to cause them to be nested. Note that the `@nest` keyword can also be aliased in the context.
raiseJsonLdError::InvalidNestValue,"nest must be a string, was #{nest.inspect}} on term #{term.inspect}"unlessnest.is_a?(String)
652
+
raiseJsonLdError::InvalidNestValue,"nest must not be a keyword other than @nest, was #{nest.inspect}} on term #{term.inspect}"ifnest.start_with?('@') && nest != '@nest'
653
+
#log_debug("") {"nest: #{nest.inspect}"}
654
+
definition.nest=nest
655
+
end
656
+
640
657
term_definitions[term]=definition
641
658
defined[term]=true
642
659
else
@@ -813,6 +830,27 @@ def content(term)
813
830
term && term.content
814
831
end
815
832
833
+
##
834
+
# Retrieve nest of a term.
835
+
# value of nest must be @nest or a term that resolves to @nest
836
+
#
837
+
# @param [Term, #to_s] term in unexpanded form
838
+
# @return [String] Nesting term
839
+
# @raise JsonLdError::InvalidNestValue if nesting term exists and is not a term resolving to `@nest` in the current context.
840
+
defnest(term)
841
+
term=find_definition(term)
842
+
ifterm
843
+
caseterm.nest
844
+
when'@nest',nil
845
+
term.nest
846
+
else
847
+
nest_term=find_definition(term.nest)
848
+
raiseJsonLdError::InvalidNestValue,"nest must a term resolving to @nest"unlessnest_term && nest_term.simple? && nest_term.id == '@nest'
849
+
term.nest
850
+
end
851
+
end
852
+
end
853
+
816
854
##
817
855
# Retrieve the language associated with a term, or the default language otherwise
0 commit comments