Sha256: 9e8b90d62788fb1c4d89c0a547cf70aaf7ea6067b230a0b24c218faff72a12af

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Hyrax
  ##
  # An {ActiveSupport::Concern} module that contains the {Hyrax::Group} logic.  It is extracted to a
  # behavior because downstream Hyku has a Hyrax::Group that inherits from ApplicationRecord.  In
  # other words it eschews the plain old Ruby object (PORO).  However, both Hyku and Hyrax's
  # {Hyrax::Group} both have notable amounts of duplicated logic.
  #
  # @see Hyrax::Group
  module GroupBehavior
    extend ActiveSupport::Concern

    DEFAULT_NAME_PREFIX = 'group/'

    class_methods do
      ##
      # @return [String]
      # @see DEFAULT_NAME_PREFIX
      def name_prefix
        DEFAULT_NAME_PREFIX
      end

      ##
      # @return [Hyrax::Group]
      def from_agent_key(key)
        new(key.delete_prefix(name_prefix))
      end
    end

    ##
    # @return [Boolean]
    def ==(other)
      other.class == self.class && other.name == name
    end

    ##
    # @return [String] a local identifier for this group; for use (e.g.) in ACL
    #   data
    def agent_key
      self.class.name_prefix + name
    end

    def to_sipity_agent
      sipity_agent || create_sipity_agent!
    end

    private

    def sipity_agent
      Sipity::Agent.find_by(proxy_for_id: name, proxy_for_type: self.class.name)
    end

    def create_sipity_agent!
      Sipity::Agent.create!(proxy_for_id: name, proxy_for_type: self.class.name)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyrax-5.1.0.pre.beta1 app/models/hyrax/group_behavior.rb
hyrax-5.0.4 app/models/hyrax/group_behavior.rb
hyrax-5.0.3 app/models/hyrax/group_behavior.rb
hyrax-5.0.2 app/models/hyrax/group_behavior.rb
hyrax-5.0.1 app/models/hyrax/group_behavior.rb
hyrax-5.0.0 app/models/hyrax/group_behavior.rb
hyrax-5.0.0.rc3 app/models/hyrax/group_behavior.rb