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.8.5.1 lib/cantango/permission_engine/parser/permissions.rb