class Hippo::Access::LockedFields

Public Class Methods

definitions() click to toggle source
# File lib/hippo/access/locked_fields.rb, line 35
def definitions
    @definitions
end
lock(klass, field, role, only=nil) click to toggle source

Lock a given class and attribute to a given role @param klass [Hippo::Model] @param field [Symbol] @param only [:read, :write]

# File lib/hippo/access/locked_fields.rb, line 31
def lock(klass, field, role, only=nil)
    @definitions[klass][field] << { role: role, only: only }
end
roles_needed_for(klass, attribute, access_type) click to toggle source

@param klass [Hippo::Model] @param field [Symbol] @param access_type [:read, :write] @return [Array<Role>] Roles that are allowed to access the field. An empty array indicates that the field is not locked and the Model should be used for determining access

# File lib/hippo/access/locked_fields.rb, line 17
def roles_needed_for(klass, attribute, access_type)
    if @definitions.has_key?(klass) && @definitions[klass].has_key?(attribute)
        @definitions[klass][attribute].each_with_object([]) do | grant, result |
            result.push(grant[:role]) if grant[:only].nil? || grant[:only] == access_type
        end
    else
        []
    end
end