Sha256: 7f3ac8151ea989f3f7056cb6bb858a7412613d498a6661c6ecd725fa0a289293
Contents?: true
Size: 1.96 KB
Versions: 1
Compression:
Stored size: 1.96 KB
Contents
module CanTango module PermissionEngine module Loader class Permissions < Base attr_accessor :permissions def initialize file_name self.file_name = file_name load! end def load_from_hash hash hash.each do |type, groups| groups.each do |group, rules| permissions[type] ||= {} parser.parse(group, rules) do |permission| permissions[type][permission.name] = permission end end end rescue => e raise "PermissionsLoader Error: The permissions for the file #{file_name} could not be loaded - cause was #{e}" end def load! yml_content.each do |type, groups| (permissions[type] = {} # This is for having fx empty users: section next) if groups.nil? # groups.each do |group, rules| permissions[type] ||= {} parser.parse(group, rules) do |permission| permissions[type][permission.name] = permission end end end rescue => e raise "PermissionsLoader Error: The permissions for the file #{file_name} could not be loaded - cause was #{e}" end def permissions @permissions ||= Hashie::Mash.new end def parser @parser ||= CanTango::PermissionEngine::Parser::Permissions.new end CanTango.config.permissions.types.each do |type| define_method(:"#{type}_permissions") { permissions.send(:"#{type}") } define_method(:"#{type}_compiled_permissions") { compiled_sum = send(:"#{type}_permissions").inject({}) do |compiled_sum, (actor, permission)| compiled_sum.merge(permission.to_compiled_hash) end Hashie::Mash.new(compiled_sum) } end include ClassMethods end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cantango-0.8.0 | lib/cantango/permission_engine/loader/permissions.rb |