@@ -856,6 +856,57 @@ def data
856856 @arch_def
857857 end
858858
859+ # given a `$ref` target, return the Ruby object
860+ #
861+ # @params uri [String] JSON Reference pointer
862+ # @return [Object] The pointed-to object
863+ def ref ( uri )
864+ raise ArgumentError , "JSON Reference must contain one '#'" unless uri . count ( "#" ) == 1
865+
866+ file_path , obj_path = uri . split ( "#" )
867+ obj =
868+ case file_path
869+ when /^certificate_class.*/
870+ cert_class_name = File . basename ( file_path , ".yaml" )
871+ cert_class ( cert_class_name )
872+ when /^certificate_model.*/
873+ cert_mode_name = File . basename ( file_path , ".yaml" )
874+ cert_model ( cert_model_name )
875+ when /^csr.*/
876+ csr_name = File . basename ( file_path , ".yaml" )
877+ csr ( csr_name )
878+ when /^ext.*/
879+ ext_name = File . basename ( file_path , ".yaml" )
880+ extension ( ext_name )
881+ when /^inst.*/
882+ inst_name = File . basename ( file_path , ".yaml" )
883+ instruction ( inst_name )
884+ when /^manual.*/
885+ manual_name = File . basename ( file_path , ".yaml" )
886+ manual ( manual_name )
887+ when /^profile_class.*/
888+ profile_class_name = File . basename ( file_path , ".yaml" )
889+ profile_class ( profile_class_name )
890+ when /^profile_release.*/
891+ profile_release_name = File . basename ( file_path , ".yaml" )
892+ profile_release ( profile_release_name )
893+ else
894+ raise "Unhandled ref object: #{ file_path } "
895+ end
896+
897+ if obj_path . nil?
898+ obj
899+ else
900+ parts = obj_path . split ( "/" )
901+ parts . each do |part |
902+ raise "Error in $ref. There is no method '#{ part } ' for a #{ obj . class . name } " unless obj . respond_to? ( part . to_sym )
903+
904+ obj = obj . send ( part )
905+ end
906+ obj
907+ end
908+ end
909+
859910 # @return [Array<Csr>] List of all implemented CSRs
860911 def implemented_csrs
861912 return @implemented_csrs unless @implemented_csrs . nil?
0 commit comments