File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -648,7 +648,26 @@ def inspect
648648 # @return [Symbol]
649649 # @since 0.3.0
650650 def __prefix__
651- __name__ . split ( '::' ) . last . downcase . to_sym
651+ instance_variable_defined? ( :@__prefix__ ) ?
652+ @__prefix__ :
653+ __name__ . split ( '::' ) . last . downcase . to_sym
654+ end
655+
656+ ##
657+ # Returns a suggested CURIE/PName prefix for this vocabulary class.
658+ #
659+ # @example Overriding a standard vocabulary prefix.
660+ # RDF::Vocab::DC.__prefix__ = :dcterms
661+ # RDF::Vocab::DC.title.pname #=> 'dcterms:title'
662+ #
663+ # @param [Symbol] prefix
664+ # @return [Symbol]
665+ # @since 3.2.3
666+ def __prefix__ = ( prefix )
667+ params = RDF ::Vocabulary . vocab_map [ __prefix__ ]
668+ @__prefix__ = prefix . to_sym
669+ RDF ::Vocabulary . register ( @__prefix__ , self , **params )
670+ @__prefix__
652671 end
653672
654673 protected
Original file line number Diff line number Diff line change 909909 end
910910
911911 context 'Vocabs outside of the RDF::Vocab namespace' do
912- uri = 'urn:x-bogus:test-vocab:'
913- TestVocab = Class . new RDF ::Vocabulary ( uri )
914- RDF ::Vocabulary . register :testvocab , TestVocab
912+ let ( :uri ) { 'urn:x-bogus:test-vocab:' }
913+ before ( :all ) {
914+ TestVocab = Class . new RDF ::Vocabulary ( 'urn:x-bogus:test-vocab:' )
915+ RDF ::Vocabulary . register :testvocab , TestVocab
916+ }
917+
915918 it 'correctly expands the pname of an arbitrary class' do
916919 expect ( RDF ::Vocabulary . expand_pname ( 'testvocab:test' ) ) . to eq ( TestVocab . test )
917920 end
921+
922+ it 'uses custom prefix' do
923+ TestVocab . __prefix__ = :tv
924+ term = RDF ::Vocabulary . expand_pname ( 'tv:test' )
925+ expect ( term ) . to eq ( TestVocab . test )
926+ expect ( term . pname ) . to eq 'tv:test'
927+ expect ( RDF ::Vocabulary . find_term ( term . to_s ) ) . to eq TestVocab . test
928+ end
918929 end
919930end
You can’t perform that action at this time.
0 commit comments