Sha256: 2c4301e909351226681026ca005f48cf41b4cce7ce476ad2e68f30c4b5753490

Contents?: true

Size: 952 Bytes

Versions: 11

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  class Group
    DEFAULT_NAME_PREFIX = 'group/'

    def self.name_prefix
      DEFAULT_NAME_PREFIX
    end

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

    def initialize(name)
      @name = name
    end

    attr_reader :name

    ##
    # @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

11 entries across 11 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/models/hyrax/group.rb
hyrax-5.0.0.rc1 app/models/hyrax/group.rb
hyrax-3.6.0 app/models/hyrax/group.rb
hyrax-4.0.0 app/models/hyrax/group.rb
hyrax-4.0.0.rc3 app/models/hyrax/group.rb
hyrax-4.0.0.rc2 app/models/hyrax/group.rb
hyrax-4.0.0.rc1 app/models/hyrax/group.rb
hyrax-3.5.0 app/models/hyrax/group.rb
hyrax-4.0.0.beta2 app/models/hyrax/group.rb
hyrax-3.4.2 app/models/hyrax/group.rb
hyrax-4.0.0.beta1 app/models/hyrax/group.rb