Class: PermissionsLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cancan-permits/loader/permissions_loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ PermissionsLoader

Returns a new instance of PermissionsLoader.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 5

def initialize file_name    
  begin
    if file_name.nil? || !File.file?(file_name)
      # raise ArgumentError, "PermissionsLoader Error: The permissions file #{file_name} could not be found" 
      # puts "PermissionsLoader Error: The permissions file #{file_name} could not be found" 
      return nil
    end

    yml_content = YAML.load_file(file_name)
    parser = PermissionsParser.new

    self.permissions ||= {}
    yml_content.each do |key, value|
      parser.parse(key, value) do |permission|
        permissions[permission.name] = permission
      end
    end
  rescue RuntimeError => e    
    raise "PermissionsLoader Error: The permissions for the file #{file_name} could not be loaded - cause was #{e}"
  end
end

Instance Attribute Details

#permissionsObject

Returns the value of attribute permissions.



3
4
5
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 3

def permissions
  @permissions
end

Class Method Details

.licenses_config_fileObject



52
53
54
55
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 52

def self.licenses_config_file
  # raise '#licenses_config_file only works in a Rails app enviroment' if !defined? Rails
  get_config_file 'licenses'
end

.load_licenses(name = nil) ⇒ Object



32
33
34
35
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 32

def self.load_licenses name = nil
  name ||= licenses_config_file
  PermissionsLoader.new name
end

.load_permits(name = nil) ⇒ Object



37
38
39
40
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 37

def self.load_permits name = nil
  name ||= permits_config_file
  PermissionsLoader.new name
end

.load_user_permissions(name = nil) ⇒ Object



27
28
29
30
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 27

def self.load_user_permissions name = nil
  name ||= user_permissions_config_file
  PermissionsLoader.new name
end

.permits_config_fileObject



42
43
44
45
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 42

def self.permits_config_file
  # raise '#user_permissions_config_file only works in a Rails app enviroment' if !defined? Rails
  get_config_file 'permits'
end

.user_permissions_config_fileObject



47
48
49
50
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 47

def self.user_permissions_config_file
  # raise '#user_permissions_config_file only works in a Rails app enviroment' if !defined? Rails
  get_config_file 'user_permissions'
end