Skip to content

Commit

Permalink
Add documentation around ActiveFedora classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jul 14, 2017
1 parent 887357d commit ee5e64c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/valkyrie/persistence/active_fedora/dynamic_klass.rb
@@ -1,6 +1,12 @@
# frozen_string_literal: true
module Valkyrie::Persistence::ActiveFedora
# A factory for Valkrie::Models given data from an ActiveFedora::Base
# Because we override `new`, no instances of DynamicKlass are actually created.
class DynamicKlass
# Instantiate the appropriate subclass of Valkrie::Model given the data from
# the `internal_model` field on the Valkyrie::Persistence::ActiveFedora::ORM::Resource class
# @param [Valkyrie::Persistence::ActiveFedora::ORM::Resource]
# @return [Valkrie::Model]
def self.new(orm_object)
orm_object.internal_model.constantize.new(cast_attributes(orm_object).merge(member_ids: orm_object.ordered_member_ids.map { |x| Valkyrie::ID.new(x) }))
end
Expand Down
2 changes: 2 additions & 0 deletions lib/valkyrie/persistence/active_fedora/orm/resource.rb
Expand Up @@ -10,6 +10,8 @@ class Schema < ActiveTriples::Schema
property :thumbnail_id, predicate: ::RDF::URI("http://example.com/thumbnail_id")
property :representative_id, predicate: ::RDF::URI("http://example.com/representative_id")
property :start_canvas, predicate: ::RDF::URI("http://example.com/start_canvas")

# The type of the valkyrie model this resource represents
property :internal_model, predicate: ::RDF::URI("http://example.com/internal_model"), multiple: false
property :file_identifiers, predicate: ::RDF::URI("http://example.com/file_identifiers")
property :label, predicate: ::RDF::URI("http://example.com/label")
Expand Down
8 changes: 8 additions & 0 deletions lib/valkyrie/persistence/active_fedora/resource_factory.rb
@@ -1,12 +1,20 @@
# frozen_string_literal: true
module Valkyrie::Persistence::ActiveFedora
# Convert Valkrie::Model to an ActiveFedora::Base and vice versa
class ResourceFactory
class << self
# Convert an ActiveFedora::Base or ActiveFedora::SolrHit to Valkrie::Model
# @param orm_object [Valkyrie::Persistence::ActiveFedora::ORM::Resource, ActiveFedora::SolrHit]
# @return [Valkrie::Model]
def to_model(orm_obj)
return solr_to_model(orm_obj) if orm_obj.is_a?(ActiveFedora::SolrHit)
::Valkyrie::Persistence::ActiveFedora::DynamicKlass.new(orm_obj)
end

# Find or create an ActiveFedora::Base that corresponds to the identifier
# of the Valkyrie model and encode the type of the Valkyrie model on it.
# @param [Valkrie::Model]
# @return [Valkyrie::Persistence::ActiveFedora::ORM::Resource]
def from_model(model)
resource =
begin
Expand Down

0 comments on commit ee5e64c

Please sign in to comment.