Class: Aegis::Normalization

Inherits:
Object
  • Object
show all
Defined in:
lib/aegis/normalization.rb

Constant Summary collapse

VERB_NORMALIZATIONS =
{
  "edit"   => "update",
  "show"   => "read",
  "list"   => "read",
  "view"   => "read",
  "delete" => "destroy",
  "remove" => "destroy"
}

Class Method Summary collapse

Class Method Details

.normalize_permission(permission) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/aegis/normalization.rb', line 17

def self.normalize_permission(permission)
  if permission =~ /^([^_]+?)_(.+?)$/
    verb, target = $1, $2
    permission = normalize_verb(verb) + "_" + target
  end
  permission
end

.normalize_verb(verb) ⇒ Object



13
14
15
# File 'lib/aegis/normalization.rb', line 13

def self.normalize_verb(verb)
  VERB_NORMALIZATIONS[verb] || verb
end