Class: Forty::Privilege::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/forty/privilege.rb

Direct Known Subclasses

Database, Schema, Table

Constant Summary collapse

PRIVILEGES =
self.constants.map { |const| self.const_get(const) }

Class Method Summary collapse

Class Method Details

.get_privilege_name_by_acronym(acronym) ⇒ Object



6
7
8
9
10
11
# File 'lib/forty/privilege.rb', line 6

def self.get_privilege_name_by_acronym(acronym)
  privilege = self.constants.select do |constant|
    self.const_get(constant).eql?(acronym)
  end[0]
  privilege.nil? ? nil : privilege.to_s.downcase
end

.parse_privileges_from_string(privileges_string) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/forty/privilege.rb', line 13

def self.parse_privileges_from_string(privileges_string)
  privileges = []
  self.constants.each do |constant|
    acronym = self.const_get(constant)
    unless privileges_string.slice!(acronym).nil?
      privileges << self.get_privilege_name_by_acronym(acronym)
    end
    break if privileges_string.empty?
  end
  privileges
end