Class: LinkedRails::Vocab
- Inherits:
-
Object
- Object
- LinkedRails::Vocab
show all
- Defined in:
- lib/linked_rails/vocab.rb
Direct Known Subclasses
Vocab
Defined Under Namespace
Classes: CustomVocabulary
Class Method Summary
collapse
Class Method Details
.app_vocabulary(key) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/linked_rails/vocab.rb', line 22
def app_vocabulary(key)
vocabulary = send(key)
LinkedRails::Vocab.define_singleton_method :app do
vocabulary
end
end
|
.define_shortcut(key) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/linked_rails/vocab.rb', line 30
def define_shortcut(key)
define_singleton_method(key) do
options = RDF::Vocabulary.vocab_map.fetch(key)
options[:class] || RDF::Vocabulary.from_sym(options[:class_name])
end
end
|
.for(iri) ⇒ Object
37
38
39
40
41
|
# File 'lib/linked_rails/vocab.rb', line 37
def for(iri)
key = vocab_map.keys.find { |k| iri.to_s.start_with?(k) }
vocab_map[key] if key
end
|
.for!(iri) ⇒ Object
43
44
45
|
# File 'lib/linked_rails/vocab.rb', line 43
def for!(iri)
self.for(iri) || raise("No vocab found for #{iri}")
end
|
.register(key, uri) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/linked_rails/vocab.rb', line 47
def register(key, uri)
klass = CustomVocabulary.new(uri)
klass.key = key.to_s.classify.upcase
RDF::Vocabulary.register(key, uri, class: klass)
vocab_map[uri.to_s] = klass
define_shortcut(key)
end
|
.register_strict(klass) ⇒ Object
57
58
59
|
# File 'lib/linked_rails/vocab.rb', line 57
def register_strict(klass)
vocab_map[klass.to_s] = klass
end
|
.vocab_map ⇒ Object
61
62
63
64
65
|
# File 'lib/linked_rails/vocab.rb', line 61
def vocab_map
return LinkedRails::Vocab.vocab_map unless self == LinkedRails::Vocab
@vocab_map ||= {}
end
|