class Permissify::Decision

The immutable result of every evaluation. Boolean helpers (‘can?`) are projections of this; enforcement (`authorize!`) reads its reason and checks. It carries only structured, safe identifiers — never arbitrary actor/resource attributes.

Attributes

checks[R]
metadata[R]
permission[R]
reason[R]

Public Class Methods

new(allowed:, permission:, reason:, checks: [], metadata: {}) click to toggle source

reason is one of:

:allowed :denied :unknown_resource :unknown_action
:unknown_permission :missing_fact :fact_error
# File lib/permissify/decision.rb, line 14
def initialize(allowed:, permission:, reason:, checks: [], metadata: {})
  @allowed    = allowed ? true : false
  @permission = permission
  @reason     = reason
  @checks     = checks.freeze
  @metadata   = metadata.freeze
  freeze
end

Public Instance Methods

allowed?(= @allowed) click to toggle source
# File lib/permissify/decision.rb, line 23
    def allowed? = @allowed
    def denied?  = !@allowed

    def to_h
      { allowed: @allowed, permission: @permission, reason: @reason,
        checks: @checks, metadata: @metadata }
    end
  end
end
denied?(= !@allowed) click to toggle source
# File lib/permissify/decision.rb, line 24
  def denied?  = !@allowed

  def to_h
    { allowed: @allowed, permission: @permission, reason: @reason,
      checks: @checks, metadata: @metadata }
  end
end
to_h() click to toggle source
# File lib/permissify/decision.rb, line 26
def to_h
  { allowed: @allowed, permission: @permission, reason: @reason,
    checks: @checks, metadata: @metadata }
end