Module: ActiveFedora::RdfNode::ClassMethods
- Defined in:
- lib/active_fedora/rdf_node.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config_for_predicate(predicate) ⇒ Object
- #create_node_accessor(name) ⇒ Object
-
#fields ⇒ Object
List of symbols representing the fields for this terminology.
- #map_predicates(&block) ⇒ Object
-
#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.
-
#rdf_type(uri_or_string = nil) ⇒ Object
Provide the value for the RDF.type of this node.
Instance Method Details
#config ⇒ Object
266 267 268 269 270 271 272 |
# File 'lib/active_fedora/rdf_node.rb', line 266 def config @config ||= if superclass.respond_to? :config superclass.config.dup else {}.with_indifferent_access end end |
#config_for_predicate(predicate) ⇒ Object
303 304 305 306 307 308 |
# File 'lib/active_fedora/rdf_node.rb', line 303 def config_for_predicate(predicate) config.each do |term, value| return term, value if value.predicate == predicate end return nil end |
#create_node_accessor(name) ⇒ Object
255 256 257 258 259 260 261 262 263 264 |
# File 'lib/active_fedora/rdf_node.rb', line 255 def create_node_accessor(name) class_eval <<-eoruby, __FILE__, __LINE__ + 1 def #{name}=(*args) set_value(rdf_subject, :#{name}, *args) end def #{name} get_values(rdf_subject, :#{name}) end eoruby end |
#fields ⇒ Object
List of symbols representing the fields for this terminology. ‘:type’ is excluded because it represents RDF.type and is a fixed value
277 278 279 |
# File 'lib/active_fedora/rdf_node.rb', line 277 def fields config.keys.map(&:to_sym) - [:type] end |
#map_predicates(&block) ⇒ Object
281 282 283 284 |
# File 'lib/active_fedora/rdf_node.rb', line 281 def map_predicates(&block) builder = Builder.new(self) builder.build &block 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
314 315 316 317 318 319 320 321 |
# File 'lib/active_fedora/rdf_node.rb', line 314 def rdf_subject &block if block_given? return @subject_block = block end # Create a B-node if they don't supply the rdf_subject @subject_block ||= lambda { |ds| RDF::Node.new } end |
#rdf_type(uri_or_string = nil) ⇒ Object
Provide the value for the RDF.type of this node
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/active_fedora/rdf_node.rb', line 292 def rdf_type(uri_or_string=nil) if uri_or_string uri = uri_or_string.kind_of?(RDF::URI) ? uri_or_string : RDF::URI.new(uri_or_string) self.config[:type] = Rdf::NodeConfig.new(:type, RDF.type) @rdf_type = uri logger.warn "Duplicate RDF Class. Trying to register #{self} for #{uri} but it is already registered for #{ActiveFedora::RdfNode.rdf_registry[uri]}" if ActiveFedora::RdfNode.rdf_registry.key? uri ActiveFedora::RdfNode.rdf_registry[uri] = self end @rdf_type end |