• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samvera / hydra-pcdm / 65136fe3-7459-42d0-8dcf-fad3664e0817

21 Apr 2023 06:52PM UTC coverage: 72.072% (-27.9%) from 100.0%
65136fe3-7459-42d0-8dcf-fad3664e0817

push

circleci

web-flow
Release 1.3.0 (#299)

160 of 222 relevant lines covered (72.07%)

8.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb
1
module Hydra::PCDM
12✔
2
  ##
3
  # Implements behavior for PCDM objects. This behavior is intended for use with
4
  # another concern completing the set of defined behavior for a PCDM class
5
  # (e.g. `PCDM::ObjectBehavior` or `PCDM::CollectionBehavior`).
6
  #
7
  # A class mixing in this behavior needs to implement {.type_validator},
8
  # returning a validator class.
9
  #
10
  # @example Defining a minimal PCDM-like thing
11
  #   class MyAbomination < ActiveFedora::Base
12
  #     def type_validator
13
  #       Hydra::PCDM::Validators::PCDMValidator
14
  #     end
15
  #
16
  #     include Hydra::PCDM::PcdmBehavior
17
  #   end
18
  #
19
  #   abom = MyAbomination.create
20
  #
21
  # @see ActiveFedora::Base
22
  # @see Hydra::PCDM::Validators
23
  module PcdmBehavior
12✔
24
    extend ActiveSupport::Concern
12✔
25

26
    included do
12✔
27
      ##
28
      # @macro [new] ordered_aggregation
29
      #   @!method $1
30
      #     @return [ActiveFedora::Associations::ContainerProxy]
31
      ordered_aggregation :members,
24✔
32
                          has_member_relation: Vocab::PCDMTerms.hasMember,
33
                          class_name: 'ActiveFedora::Base',
34
                          type_validator: type_validator,
35
                          through: :list_source
36

37
      ##
38
      # @macro [new] indirectly_contains
39
      #   @!method $1
40
      #     @return [ActiveFedora::Associations::ContainerProxy]
41
      indirectly_contains :related_objects, has_member_relation: RDF::Vocab::ORE.aggregates,
24✔
42
                                            inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base',
43
                                            through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target,
44
                                            type_validator: Validators::PCDMObjectValidator
45

46
      ##
47
      # @macro [new] indirectly_contains
48
      #   @!method $1
49
      #     @return [ActiveFedora::Associations::ContainerProxy]
50
      indirectly_contains :member_of_collections,
24✔
51
                          has_member_relation: Vocab::PCDMTerms.memberOf,
52
                          inserted_content_relation: RDF::Vocab::ORE.proxyFor,
53
                          class_name: 'ActiveFedora::Base',
54
                          through: 'ActiveFedora::Aggregation::Proxy',
55
                          foreign_key: :target,
56
                          type_validator: Validators::PCDMCollectionValidator
57
    end
58

59
    ##
60
    # @see ActiveSupport::Concern
61
    module ClassMethods
12✔
62
      ##
63
      # @return [#validate!] a validator object
64
      def type_validator
12✔
65
        @type_validator ||= Validators::CompositeValidator.new(
24✔
66
          super,
67
          Validators::PCDMValidator,
68
          Validators::AncestorValidator
69
        )
70
      end
71
    end
72

73
    ##
74
    # @return [Enumerable<ActiveFedora::Base>]
75
    def member_of
12✔
76
      return [] if id.nil?
×
77
      ActiveFedora::Base.where(Config.indexing_member_ids_key => id)
×
78
    end
79

80
    ##
81
    # Gives the subset of #members that are PCDM objects
82
    #
83
    # @return [Enumerable<PCDM::ObjectBehavior>] an enumerable over the members
84
    #   that are PCDM objects
85
    def objects
12✔
86
      members.select(&:pcdm_object?)
×
87
    end
88

89
    ##
90
    # Gives a subset of #member_ids, where all elements are PCDM objects.
91
    # @return [Enumerable<String>] the object ids
92
    def object_ids
12✔
93
      objects.map(&:id)
×
94
    end
95

96
    ##
97
    # Gives a subset of {#ordered_members}, where all elements are PCDM objects.
98
    #
99
    # @return [Enumerable<PCDM::ObjectBehavior>]
100
    def ordered_objects
12✔
101
      ordered_members.to_a.select(&:pcdm_object?)
×
102
    end
103

104
    ##
105
    # @return [Enumerable<String>] an ordered list of member ids
106
    def ordered_object_ids
12✔
107
      ordered_objects.map(&:id)
×
108
    end
109

110
    ##
111
    # @return [Enumerable<Hydra::PCDM::CollectionBehavior>] the collections the
112
    #   object is a member of.
113
    def in_collections
12✔
114
      member_of.select(&:pcdm_collection?).to_a
×
115
    end
116

117
    # @return [Enumerable<String>] ids for collections the object is a member of
118
    def in_collection_ids
12✔
119
      in_collections.map(&:id)
×
120
    end
121

122
    ##
123
    # @param [ActiveFedora::Base] potential_ancestor  the resource to check for
124
    #   ancestorship
125
    # @return [Boolean] whether the argument is an ancestor of the object
126
    def ancestor?(potential_ancestor)
12✔
127
      ::Hydra::PCDM::AncestorChecker.former_is_ancestor_of_latter?(potential_ancestor, self)
×
128
    end
129
  end
130
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc