Class: CanTango::PermissionEngine::Loader::Permissions

Inherits:
Base
  • Object
show all
Defined in:
lib/cantango/permission_engine/loader/permissions.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#file_name

Instance Method Summary collapse

Methods inherited from Base

inherited, #yml_content

Constructor Details

#initialize(file_name) ⇒ Permissions

Returns a new instance of Permissions.



7
8
9
10
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 7

def initialize file_name
  @file_name = file_name
  load!
end

Instance Attribute Details

#permissionsObject

Returns the value of attribute permissions.



5
6
7
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 5

def permissions
  @permissions
end

Instance Method Details

#load!Object



27
28
29
30
31
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 27

def load!
  load_from_hash yml_content
rescue => e
  raise "PermissionsLoader Error: The permissions for the file #{file_name} could not be loaded - cause was #{e}"
end

#load_from_hash(hash) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 12

def load_from_hash hash
  return if hash.empty?
  hash.each do |type, groups|
    permissions[type] ||= {}

    next if groups.nil?

    groups.each do |group, rules|
      parser.parse(group, rules) do |permission|
        permissions[type][permission.name] = permission
      end
    end
  end
end

#parserObject



37
38
39
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 37

def parser
  @parser ||= CanTango::PermissionEngine::Parser::Permissions.new
end