Module: ActiveFedora::RdfNode::ClassMethods

Defined in:
lib/active_fedora/rdf_node.rb

Instance Method Summary collapse

Instance Method Details

#configObject



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

#fieldsObject

List of symbols representing the fields for this terminology. ‘:type’ is excluded because it represents RDF.type and is a fixed value

See Also:



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

Yields:

  • (ds)

    ‘ds’ is the datastream instance



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

Examples:

class Location 
  include ActiveFedora::RdfObject
  rdf_type RDF::EbuCore.Location
end


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