Class: Etna::Permissions
- Inherits:
-
Object
- Object
- Etna::Permissions
- Defined in:
- lib/etna/permissions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_permission(permission) ⇒ Object
- #any?(&block) ⇒ Boolean
-
#initialize(permissions) ⇒ Permissions
constructor
A new instance of Permissions.
- #to_hash ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(permissions) ⇒ Permissions
Returns a new instance of Permissions.
3 4 5 |
# File 'lib/etna/permissions.rb', line 3 def initialize() @permissions = end |
Class Method Details
.from_encoded_permissions(encoded_permissions) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/etna/permissions.rb', line 7 def self.() perms = .split(/\;/).map do |roles| role, projects = roles.split(/:/) projects.split(/\,/).reduce([]) do |perms, project_name| perms << Etna::Permission.new(role, project_name) end end.flatten Etna::Permissions.new(perms) end |
.from_hash(permissions_hash) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/etna/permissions.rb', line 19 def self.from_hash() perms = .map do |project_name, role_hash| Etna::Permission.new( Etna::Role.new(role_hash[:role], role_hash[:restricted]).key, project_name ) end Etna::Permissions.new(perms) end |
Instance Method Details
#add_permission(permission) ⇒ Object
47 48 49 50 51 |
# File 'lib/etna/permissions.rb', line 47 def () return if current_project_names.include?(.project_name) @permissions << end |
#any?(&block) ⇒ Boolean
53 54 55 |
# File 'lib/etna/permissions.rb', line 53 def any?(&block) @permissions.any?(&block) end |
#to_hash ⇒ Object
41 42 43 44 45 |
# File 'lib/etna/permissions.rb', line 41 def to_hash @permissions_hash ||= @permissions.map do || [.project_name, .to_hash] end.to_h end |
#to_string ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/etna/permissions.rb', line 30 def to_string @permissions_string ||= @permissions.group_by(&:role_key) .sort_by(&:first) .map do |role_key, | [ role_key, .map(&:project_name).sort.join(","), ].join(":") end.join(";") end |