Module: Hydra::PCDM::PcdmBehavior

Extended by:
ActiveSupport::Concern
Defined in:
lib/hydra/pcdm/models/concerns/pcdm_behavior.rb

Overview

Implements behavior for PCDM objects. This behavior is intended for use with another concern completing the set of defined behavior for a PCDM class (e.g. ‘PCDM::ObjectBehavior` or `PCDM::CollectionBehavior`).

A class mixing in this behavior needs to implement type_validator, returning a validator class.

Examples:

Defining a minimal PCDM-like thing

class MyAbomination < ActiveFedora::Base
  def type_validator
    Hydra::PCDM::Validators::PCDMValidator
  end

  include Hydra::PCDM::PcdmBehavior
end

abom = MyAbomination.create

See Also:

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#ancestor?(potential_ancestor) ⇒ Boolean

Returns whether the argument is an ancestor of the object.

Parameters:

  • potential_ancestor (ActiveFedora::Base)

    the resource to check for ancestorship

Returns:

  • (Boolean)

    whether the argument is an ancestor of the object



126
127
128
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 126

def ancestor?(potential_ancestor)
  ::Hydra::PCDM::AncestorChecker.former_is_ancestor_of_latter?(potential_ancestor, self)
end

#in_collection_idsEnumerable<String>

Returns ids for collections the object is a member of.

Returns:

  • (Enumerable<String>)

    ids for collections the object is a member of



118
119
120
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 118

def in_collection_ids
  in_collections.map(&:id)
end

#in_collectionsEnumerable<Hydra::PCDM::CollectionBehavior>

Returns the collections the object is a member of.

Returns:



113
114
115
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 113

def in_collections
  member_of.select(&:pcdm_collection?).to_a
end

#member_ofEnumerable<ActiveFedora::Base>

Returns:

  • (Enumerable<ActiveFedora::Base>)


75
76
77
78
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 75

def member_of
  return [] if id.nil?
  ActiveFedora::Base.where(Config.indexing_member_ids_key => id)
end

#object_idsEnumerable<String>

Gives a subset of #member_ids, where all elements are PCDM objects.

Returns:

  • (Enumerable<String>)

    the object ids



92
93
94
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 92

def object_ids
  objects.map(&:id)
end

#objectsEnumerable<PCDM::ObjectBehavior>

Gives the subset of #members that are PCDM objects

Returns:



85
86
87
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 85

def objects
  members.select(&:pcdm_object?)
end

#ordered_object_idsEnumerable<String>

Returns an ordered list of member ids.

Returns:

  • (Enumerable<String>)

    an ordered list of member ids



106
107
108
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 106

def ordered_object_ids
  ordered_objects.map(&:id)
end

#ordered_objectsEnumerable<PCDM::ObjectBehavior>

Gives a subset of #ordered_members, where all elements are PCDM objects.

Returns:



100
101
102
# File 'lib/hydra/pcdm/models/concerns/pcdm_behavior.rb', line 100

def ordered_objects
  ordered_members.to_a.select(&:pcdm_object?)
end