Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module ActiveFedora | ||
|
||
# Attributes delegated to ActiveTriples. Allows ActiveFedora to track all attributes consistently. | ||
# | ||
# @example | ||
# class Book < ActiveFedora::Base | ||
# property :title, predicate: ::RDF::DC.title | ||
# property :author, predicate: ::RDF::DC.creator | ||
# end | ||
# | ||
# Book.attribute_names | ||
# => ["title", "author"] | ||
|
||
class ActiveTripleAttribute < DelegatedAttribute | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module ActiveFedora | ||
|
||
# Class for attributes that are delegated to an OmDatastream | ||
|
||
class OmAttribute < StreamAttribute | ||
|
||
# @param [ActiveFedora::Base] obj the object that has the attribute | ||
# @param [Object] v value to write to the attribute | ||
def writer(obj, v) | ||
ds = file_for_attribute(obj, delegate_target) | ||
obj.mark_as_changed(field) if obj.value_has_changed?(field, v) | ||
terminology = at || [field] | ||
ds.send(:update_indexed_attributes, {terminology => v}) | ||
end | ||
|
||
# @param [ActiveFedora::Base] obj the object that has the attribute | ||
# @param [Object] opts extra options that are passed to the target reader | ||
def reader(obj, *opts) | ||
ds = file_for_attribute(obj, delegate_target) | ||
terminology = at || [field] | ||
if terminology.length == 1 && opts.present? | ||
ds.send(terminology.first, *opts) | ||
else | ||
ds.send(:term_values, *terminology) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module ActiveFedora | ||
|
||
# Class for attributes that are delegated to a RDFDatastream | ||
|
||
class RdfDatastreamAttribute < StreamAttribute | ||
|
||
# @param [ActiveFedora::Base] obj the object that has the attribute | ||
# @param [Object] v value to write to the attribute | ||
def writer(obj, v) | ||
node = file_for_attribute(obj, delegate_target) | ||
obj.mark_as_changed(field) if obj.value_has_changed?(field, v) | ||
term = if at | ||
vals = at.dup | ||
while vals.length > 1 | ||
node = node.send(vals.shift) | ||
node = node.build if node.empty? | ||
node = node.first | ||
end | ||
vals.first | ||
else | ||
field | ||
end | ||
node.send("#{term}=", v) | ||
end | ||
|
||
# @param [ActiveFedora::Base] obj the object that has the attribute | ||
def reader(obj) | ||
node = file_for_attribute(obj, delegate_target) | ||
term = if at | ||
vals = at.dup | ||
while vals.length > 1 | ||
node = node.send(vals.shift) | ||
node = if node.empty? | ||
node.build | ||
else | ||
node.first | ||
end | ||
end | ||
vals.first | ||
else | ||
field | ||
end | ||
node.send(term) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module ActiveFedora | ||
|
||
# Abstract class for attributes that are delegated to a serialized representation such as a NonRDFSource | ||
# | ||
# @abstract | ||
# @attr [String] delegate_target | ||
# @attr [String] at | ||
# @attr [String] target_class | ||
|
||
class StreamAttribute < DelegatedAttribute | ||
|
||
attr_accessor :delegate_target, :at, :target_class | ||
|
||
# @param [Symbol] field the field to find or create | ||
# @param [Hash] args | ||
# @option args [String] :delegate_target the path to the delegate | ||
# @option args [Class] :klass the class to create | ||
# @option args [true,false] :multiple (false) true for multi-value fields | ||
# @option args [Array<Symbol>] :at path to a deep node | ||
def initialize(field, args={}) | ||
super | ||
self.delegate_target = args.fetch(:delegate_target) | ||
self.target_class = args.fetch(:klass) | ||
self.at = args.fetch(:at, nil) | ||
end | ||
|
||
# Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first | ||
def primary_solr_name | ||
@datastream ||= target_class.new | ||
raise NoMethodError, "the file '#{target_class}' doesn't respond to 'primary_solr_name'" unless @datastream.respond_to?(:primary_solr_name) | ||
@datastream.primary_solr_name(field, delegate_target) | ||
end | ||
|
||
def type | ||
raise NoMethodError, "the file '#{target_class}' doesn't respond to 'type'" unless target_class.respond_to?(:type) | ||
target_class.type(field) | ||
end | ||
|
||
private | ||
|
||
def file_for_attribute(obj, delegate_target) | ||
obj.attached_files[delegate_target] || raise(ArgumentError, "Undefined file: `#{delegate_target}' in property #{field}") | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters