Class: Hyrax::VisibilityMap

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
app/services/hyrax/visibility_map.rb

Overview

Defines a map from a visibility string value to appropriate permissions representing that visibility.

Constant Summary collapse

DEFAULT_MAP =
{
  Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC => {
    permission: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC,
    additions: [Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC].freeze,
    deletions: [].freeze
  }.freeze,
  Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED => {
    permission: Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED,
    additions: [Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED].freeze,
    deletions: [Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC].freeze
  }.freeze,
  Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE => {
    permission: :PRIVATE,
    additions: [].freeze,
    deletions: [Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC,
                Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED].freeze
  }.freeze
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map: DEFAULT_MAP) ⇒ VisibilityMap

Returns a new instance of VisibilityMap.

Parameters:

  • map (Hash<String, String>) (defaults to: DEFAULT_MAP)

43
44
45
# File 'app/services/hyrax/visibility_map.rb', line 43

def initialize(map: DEFAULT_MAP)
  @map = map
end

Instance Attribute Details

#mapObject (readonly)

Returns the value of attribute map


39
40
41
# File 'app/services/hyrax/visibility_map.rb', line 39

def map
  @map
end

Instance Method Details

#additions_for(visibility:) ⇒ Object


53
54
55
# File 'app/services/hyrax/visibility_map.rb', line 53

def additions_for(visibility:)
  self[visibility][:additions]
end

#deletions_for(visibility:) ⇒ Object


57
58
59
# File 'app/services/hyrax/visibility_map.rb', line 57

def deletions_for(visibility:)
  self[visibility][:deletions]
end

#visibilitiesObject


61
62
63
# File 'app/services/hyrax/visibility_map.rb', line 61

def visibilities
  @map.keys
end

#visibility_for(group:) ⇒ Object

Reverse lookup a visibility stirng from the permission group value


49
50
51
# File 'app/services/hyrax/visibility_map.rb', line 49

def visibility_for(group:)
  @map.find { |_, v| v[:permission] == group }&.first
end