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
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #config ⇒ Object
- #config_for_term_or_uri(term) ⇒ Object
- #fields ⇒ Object
- #map_predicates {|mapper| ... } ⇒ Object
-
#property(name, opts = {}) {|index| ... } ⇒ Object
Registers properties for Resource-like classes.
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
20 21 22 |
# File 'lib/active_fedora/rdf/properties.rb', line 20 def properties @properties end |
Instance Method Details
#config ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/active_fedora/rdf/properties.rb', line 52 def config @config ||= if superclass.respond_to? :config superclass.properties.dup else {}.with_indifferent_access end end |
#config_for_term_or_uri(term) ⇒ Object
60 61 62 63 |
# File 'lib/active_fedora/rdf/properties.rb', line 60 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 |
#fields ⇒ Object
65 66 67 |
# File 'lib/active_fedora/rdf/properties.rb', line 65 def fields properties.keys.map(&:to_sym) end |
#map_predicates {|mapper| ... } ⇒ Object
101 102 103 104 105 |
# File 'lib/active_fedora/rdf/properties.rb', line 101 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_fedora/rdf/properties.rb', line 27 def property(name, opts={}, &block) 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? self.properties[name] = { behaviors: behaviors, type: config[name].type, class_name: config[name].class_name, predicate: config[name].predicate, term: config[name].term, multivalue: config[name].multivalue } register_property(name) end |