Class: CanTango::PermissionEngine::Loader::Permissions
- Includes:
- ClassMethods
- Defined in:
- lib/cantango/permission_engine/loader/permissions.rb
Instance Attribute Summary collapse
-
#permissions ⇒ Object
Returns the value of attribute permissions.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(file_name) ⇒ Permissions
constructor
A new instance of Permissions.
- #load! ⇒ Object
- #load_from_hash(hash) ⇒ Object
- #parser ⇒ Object
Methods inherited from Base
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 self.file_name = file_name load! end |
Instance Attribute Details
#permissions ⇒ Object
Returns the value of attribute permissions.
5 6 7 |
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 5 def @permissions end |
Instance Method Details
#load! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 26 def load! return if yml_content.empty? yml_content.each do |type, groups| ([type] = {} # This is for having fx empty users: section next) if groups.nil? # groups.each do |group, rules| [type] ||= {} parser.parse(group, rules) do || [type][.name] = end end end 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 |
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 12 def load_from_hash hash return if hash.empty? hash.each do |type, groups| groups.each do |group, rules| [type] ||= {} parser.parse(group, rules) do || [type][.name] = end end end rescue => e raise "PermissionsLoader Error: The permissions for the file #{file_name} could not be loaded - cause was #{e}" end |
#parser ⇒ Object
46 47 48 |
# File 'lib/cantango/permission_engine/loader/permissions.rb', line 46 def parser @parser ||= CanTango::PermissionEngine::Parser::Permissions.new end |