Skip to content

Instantly share code, notes, and snippets.

@elrayle
Last active August 29, 2015 14:23
Show Gist options
  • Save elrayle/e5eba35a623909488ee1 to your computer and use it in GitHub Desktop.
Save elrayle/e5eba35a623909488ee1 to your computer and use it in GitHub Desktop.
# MODIFICATIONS to object code
module Hydra::PCDM
class ObjectBehavior
# pcdm:hasMember objects
aggregates :members, predicate: RDFVocabularies::PCDMTerms.hasMember,
class_name: "ActiveFedora::Base"
# ore:aggregates related objects
indirectly_contains :related_objects, has_member_relation: RDF::Vocab::ORE.aggregates,
inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: "ActiveFedora::Base",
through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target
# pcdm:hasMember (or pcdm:hasOrder) orders
indirectly_contains :orders, has_member_relation: RDFVocabularies::PCDMTerms.hasMember,
inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: "ActiveFedora::Base",
through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target
# pcdm:hasFile files
directly_contains :files, has_member_relation: RDFVocabularies::PCDMTerms.hasFile,
class_name: "Hydra::PCDM::File"
end
end
# NEW class for pcdm:order
module Hydra::PCDM
class Order < ActiveFedora::Base
include Hydra::PCDM::ObjectBehavior # inherit all behaviors of pcdm:object
include Hydra::PCDM::OrderBehavior
end
end
# NEW class for pcdm:order behaviors
module Hydra::PCDM
module OrderBehavior
extend ActiveSupport::Concern
# override method to prevent orders from having orders which was inherited from pcdm:object
def orders=
end
def orders
end
# NO ADDITIONAL BEHAVIORS BEYOND PCDM:OBJECT that I can think of... are there any?
# Services provide actions and validations
end
end
# NEW SERVICES
module Hydra::PCDM
class CreateOrder
##
# Create a new order for an object.
# @param [Hydra::PCDM::Object] :parent_object to which to add order
# @return [Hydra::PCDM::Order] the new pcdm order
def self.call( parent_object )
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
child_order = Hydra::PCDM::Order.new
parent_object.orders << child_order
end
end
end
module Hydra::PCDM
class AddObjectToOrder
##
# Add a new order for an object.
# @param [Hydra::PCDM::Object] :parent_object in which the child_object and order live
# @param [Hydra::PCDM::Object] :order referencing the child_object
# @param [Hydra::PCDM::Object] :child_object to which to add order
# @return [Hydra::PCDM::Order] the updated pcdm order
def self.call( parent_object )
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
raise ArgumentError, "child_object must be a pcdm object" unless Hydra::PCDM.object? child_object
raise ArgumentError, "order must be a pcdm order" unless Hydra::PCDM.order? order
raise ArgumentError, "child_object must be a member of parent_object" unless parent_object.has_member? child_object
raise ArgumentError, "order must be an order for parent_object" unless parent_object.has_order? order
order.members << child_order
end
end
end
module Hydra::PCDM
class GetOrdersFromObject
##
# Add a new order for an object.
# @param [Hydra::PCDM::Object] :parent_object in which the child_object and order live
# @return [Hydra::PCDM::Order] the pcdm orders
def self.call( parent_object )
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
parent_object.orders
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment