Class: Hyrax::VisibilityMap
- Inherits:
-
Object
- Object
- Hyrax::VisibilityMap
- 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.
Defined Under Namespace
Classes: UnknownVisibility
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
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
- #additions_for(visibility:) ⇒ Object
- #deletions_for(visibility:) ⇒ Object
- #fetch(key, &block) ⇒ Object
-
#initialize(map: DEFAULT_MAP) ⇒ VisibilityMap
constructor
A new instance of VisibilityMap.
- #visibilities ⇒ Object
-
#visibility_for(group:) ⇒ Object
Reverse lookup a visibility stirng from the permission group value.
Constructor Details
#initialize(map: DEFAULT_MAP) ⇒ VisibilityMap
Returns a new instance of VisibilityMap.
43 44 45 |
# File 'app/services/hyrax/visibility_map.rb', line 43 def initialize(map: DEFAULT_MAP) @map = map end |
Instance Attribute Details
#map ⇒ Object (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:) fetch(visibility)&.fetch(:additions) end |
#deletions_for(visibility:) ⇒ Object
57 58 59 |
# File 'app/services/hyrax/visibility_map.rb', line 57 def deletions_for(visibility:) fetch(visibility)&.fetch(:deletions) end |
#fetch(key, &block) ⇒ Object
61 62 63 64 65 |
# File 'app/services/hyrax/visibility_map.rb', line 61 def fetch(key, &block) @map.fetch(key, &block) rescue KeyError => e raise(UnknownVisibility, e.) end |
#visibilities ⇒ Object
67 68 69 |
# File 'app/services/hyrax/visibility_map.rb', line 67 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 |