Module: ActiveFedora::RDFDatastream::ModelMethods::ClassMethods
- Defined in:
- lib/active_fedora/rdf_datastream.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/active_fedora/rdf_datastream.rb', line 68
def method_missing(name, *args, &block)
args = args.first if args.respond_to? :first
raise "mapping must specify RDF vocabulary as :in argument" unless args.has_key? :in
vocab = args[:in]
predicate = args.fetch(:to, name)
raise "Vocabulary '#{vocab.inspect}' does not define property '#{predicate.inspect}'" unless vocab.respond_to? predicate
indexing = false
if block_given?
indexing = true
iobj = IndexObject.new
yield iobj
data_type = iobj.data_type
behaviors = iobj.behaviors
end
vocab = vocab.to_s
name = self.prefix(name)
if config
if config[:predicate_mapping].has_key? vocab
config[:predicate_mapping][vocab][name] = predicate
else
config[:predicate_mapping][vocab] = { name => predicate }
end
config[:predicate_mapping][vocab]["#{name}__type".to_sym] = data_type if indexing
config[:predicate_mapping][vocab]["#{name}__behaviors".to_sym] = behaviors if indexing
else
config = {
:default_namespace => vocab,
:predicate_mapping => {
vocab => { name => predicate }
}
}
config[:predicate_mapping][vocab]["#{name}__type".to_sym] = data_type if indexing
config[:predicate_mapping][vocab]["#{name}__behaviors".to_sym] = behaviors if indexing
end
end
|
Instance Attribute Details
#vocabularies ⇒ Object
Returns the value of attribute vocabularies.
30
31
32
|
# File 'lib/active_fedora/rdf_datastream.rb', line 30
def vocabularies
@vocabularies
end
|
Instance Method Details
#map_predicates {|_self| ... } ⇒ Object
65
66
67
|
# File 'lib/active_fedora/rdf_datastream.rb', line 65
def map_predicates(&block)
yield self
end
|
#prefix(name) ⇒ Object
34
35
36
37
38
|
# File 'lib/active_fedora/rdf_datastream.rb', line 34
def prefix(name)
name = name.to_s unless name.is_a? String
pre = self.to_s.sub(/RDFDatastream$/i, '').underscore
return "#{pre}__#{name}".to_sym
end
|
#rdf_subject {|ds| ... } ⇒ Object
Register a ruby block that evaluates to the subject of the graph By default, the block returns the current object’s pid
44
45
46
47
48
49
50
|
# File 'lib/active_fedora/rdf_datastream.rb', line 44
def rdf_subject &block
if block_given?
return @subject_block = block
end
@subject_block ||= lambda { |ds| "info:fedora/#{ds.pid}" }
end
|
#register_vocabularies(*vocabs) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/active_fedora/rdf_datastream.rb', line 52
def register_vocabularies(*vocabs)
@vocabularies ||= {}
vocabs.each do |v|
if v.is_a?(RDF::Vocabulary) or (v.respond_to? :property and v.respond_to? :to_uri)
@vocabularies[v.to_uri] = v
else
raise "not an RDF vocabulary: #{v}"
end
end
ActiveFedora::Predicates.vocabularies(@vocabularies)
@vocabularies
end
|