Class: PermissionsLoader
- Inherits:
-
Object
- Object
- PermissionsLoader
- Defined in:
- lib/cancan-permits/loader/permissions_loader.rb
Instance Attribute Summary collapse
-
#permissions ⇒ Object
Returns the value of attribute permissions.
Class Method Summary collapse
- .licenses_config_file ⇒ Object
- .load_licenses(name = nil) ⇒ Object
- .load_permits(name = nil) ⇒ Object
- .load_user_permissions(name = nil) ⇒ Object
- .permits_config_file ⇒ Object
- .user_permissions_config_file ⇒ Object
Instance Method Summary collapse
-
#initialize(file_name) ⇒ PermissionsLoader
constructor
A new instance of PermissionsLoader.
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. ||= {} yml_content.each do |key, value| parser.parse(key, value) do || [.name] = 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
#permissions ⇒ Object
Returns the value of attribute permissions.
3 4 5 |
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 3 def @permissions end |
Class Method Details
.licenses_config_file ⇒ Object
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. name = nil name ||= PermissionsLoader.new name end |
.permits_config_file ⇒ Object
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_file ⇒ Object
47 48 49 50 |
# File 'lib/cancan-permits/loader/permissions_loader.rb', line 47 def self. # raise '#user_permissions_config_file only works in a Rails app enviroment' if !defined? Rails get_config_file 'user_permissions' end |