Sha256: bbad18fdb10185f1a4416f0e99df2cb91e9040a7a5282501753e4f0c6655cfe6

Contents?: true

Size: 997 Bytes

Versions: 21

Compression:

Stored size: 997 Bytes

Contents

module CanTango
  class PermissionEngine < Engine
    module Parser
      class Permissions

        def initialize
        end

        def parse(key, obj, &blk)
          permission = CanTango::PermissionEngine::Permission.new key
          case obj
          when Hash
            parse_permission(obj, permission, &blk)
          else
            raise "Each key must have a YAML hash that defines its permission configuration"
          end
          yield permission if blk
        end

        protected

        # set :can and :cannot on permission with the permission rule
        def parse_permission(obj, permission, &blk)
          # Forget keys because I don't know what to do with them
          obj.each do |key, value|
            raise ArgumentError, "A CanTango permissions .yml file can only have the keys can: and cannot:" if ![:can, :cannot].include?(key.to_sym)
            permission.static_rules.send :"#{key}=", value
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
cantango-0.9.4.7 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4.6 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4.5 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4.3 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4.2 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4.1 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.4 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.9.3.2 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9.5 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9.4 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9.3 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9.2 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9.1 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.9 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.8.1 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.8 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.7 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.6.2 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.6.1 lib/cantango/permission_engine/parser/permissions.rb
cantango-0.8.6 lib/cantango/permission_engine/parser/permissions.rb