Module: ActiveFedora::Rdf::Properties

Extended by:
Deprecation
Included in:
ActiveFedora::RDFDatastream, List, Resource
Defined in:
lib/active_fedora/rdf/properties.rb

Overview

Implements property configuration common to Rdf::Resource, RDFDatastream, and others. It does its work at the class level, and is meant to be extended.

Define properties at the class level with:

property :title, predicate: RDF::DC.title, class_name: ResourceClass

or with the ‘old’ style:

map_predicates do |map|
  map.title(in: RDF::DC)
end

You can pass a block to either to set index behavior.

Defined Under Namespace

Classes: Mapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject Also known as: properties

Returns the value of attribute config.



20
21
22
# File 'lib/active_fedora/rdf/properties.rb', line 20

def config
  @config
end

Instance Method Details

#config_for_term_or_uri(term) ⇒ Object



46
47
48
49
# File 'lib/active_fedora/rdf/properties.rb', line 46

def config_for_term_or_uri(term)
  return config[term.to_sym] unless term.kind_of? RDF::Resource
  config.each { |k, v| return v if v.predicate == term.to_uri }
end

#fieldsObject



51
52
53
# File 'lib/active_fedora/rdf/properties.rb', line 51

def fields
  properties.keys.map(&:to_sym)
end

#map_predicates {|mapper| ... } ⇒ Object

Yields:

  • (mapper)


87
88
89
90
91
# File 'lib/active_fedora/rdf/properties.rb', line 87

def map_predicates
  Deprecation.warn Properties, "map_predicates is deprecated and will be removed in active-fedora 8.0.0. Use property :name, predicate: predicate instead.", caller
  mapper = Mapper.new(self)
  yield(mapper)
end

#property(name, opts = {}) {|index| ... } ⇒ Object

Registers properties for Resource-like classes

Parameters:

  • name (Symbol)

    of the property (and its accessor methods)

  • opts (Hash) (defaults to: {})

    for this property, must include a :predicate

Yields:

  • (index)

    index sets solr behaviors for the property



27
28
29
30
31
32
33
# File 'lib/active_fedora/rdf/properties.rb', line 27

def property(name, opts={}, &block)
  self.config[name] = ActiveFedora::Rdf::NodeConfig.new(name, opts[:predicate], opts.except(:predicate)).tap do |config|
    config.with_index(&block) if block_given?
  end
  behaviors = config[name].behaviors.flatten if config[name].behaviors and not config[name].behaviors.empty?
  register_property(name)
end